-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Centralized error throwing for encryption key #3105
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc0be05
Centralized error throwing for encryption key
krynble cca7c99
Unifying the error message used by cli and core packages
krynble f53b793
Improvements to error messages to make it more DRY
krynble 6d6b872
Removed unnecessary throw
krynble 2c2d2ff
:twisted_rightwards_arrows: Merge master
ivov 9b5d3d6
Throwing error when credential does not exist to simplify node behavi…
krynble File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
import { RESPONSE_ERROR_MESSAGES as CORE_RESPONSE_ERROR_MESSAGES } from 'n8n-core'; | ||
|
||
export const RESPONSE_ERROR_MESSAGES = { | ||
NO_CREDENTIAL: 'Credential not found', | ||
NO_ENCRYPTION_KEY: 'Encryption key missing to decrypt credentials', | ||
NO_ENCRYPTION_KEY: CORE_RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, | ||
}; | ||
|
||
export const AUTH_COOKIE_NAME = 'n8n-auth'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import type { CredentialPayload, SaveCredentialFunction } from './shared/types'; | |
import type { Role } from '../../src/databases/entities/Role'; | ||
import type { User } from '../../src/databases/entities/User'; | ||
import * as testDb from './shared/testDb'; | ||
import { RESPONSE_ERROR_MESSAGES } from '../../src/constants'; | ||
import { CredentialsEntity } from '../../src/databases/entities/CredentialsEntity'; | ||
|
||
jest.mock('../../src/telemetry'); | ||
|
@@ -91,7 +92,7 @@ test('POST /credentials should fail with invalid inputs', async () => { | |
|
||
test('POST /credentials should fail with missing encryption key', async () => { | ||
const mock = jest.spyOn(UserSettings, 'getEncryptionKey'); | ||
mock.mockResolvedValue(undefined); | ||
mock.mockRejectedValue(new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY)); | ||
|
||
const ownerShell = await testDb.createUserShell(globalOwnerRole); | ||
const authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell }); | ||
|
@@ -354,7 +355,8 @@ test('PATCH /credentials/:id should fail if cred not found', async () => { | |
|
||
test('PATCH /credentials/:id should fail with missing encryption key', async () => { | ||
const mock = jest.spyOn(UserSettings, 'getEncryptionKey'); | ||
mock.mockResolvedValue(undefined); | ||
mock.mockRejectedValue(new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also check for the correct messages in the tests? |
||
|
||
|
||
const ownerShell = await testDb.createUserShell(globalOwnerRole); | ||
const authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell }); | ||
|
@@ -504,7 +506,8 @@ test('GET /credentials/:id should fail with missing encryption key', async () => | |
const savedCredential = await saveCredential(credentialPayload(), { user: ownerShell }); | ||
|
||
const mock = jest.spyOn(UserSettings, 'getEncryptionKey'); | ||
mock.mockResolvedValue(undefined); | ||
mock.mockRejectedValue(new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY)); | ||
|
||
|
||
const response = await authOwnerAgent | ||
.get(`/credentials/${savedCredential.id}`) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref comment in
UserSettings.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IN this case specifically we're changing the regular error to a new type of error, so this try / catch block is still necessary