-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
28 changed files
with
324 additions
and
123 deletions.
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
26 changes: 26 additions & 0 deletions
26
apps/server/src/modules/oauth/loggable/auth-code-failure-loggable-exception.spec.ts
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AuthCodeFailureLoggableException } from './auth-code-failure-loggable-exception'; | ||
|
||
describe(AuthCodeFailureLoggableException.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const errorCode = 'error_code'; | ||
const exception = new AuthCodeFailureLoggableException(errorCode); | ||
return { errorCode, exception }; | ||
}; | ||
|
||
it('should return a LogMessage', () => { | ||
const { errorCode, exception } = setup(); | ||
|
||
const logMessage = exception.getLogMessage(); | ||
|
||
expect(logMessage).toEqual({ | ||
type: 'SSO_AUTH_CODE_STEP', | ||
message: 'Authorization Query Object has no authorization code or error', | ||
stack: exception.stack, | ||
data: { | ||
errorCode, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
apps/server/src/modules/oauth/loggable/auth-code-failure-loggable-exception.ts
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ErrorLogMessage, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; | ||
import { OauthSsoErrorLoggableException } from './oauth-sso-error-loggable-exception'; | ||
|
||
export class AuthCodeFailureLoggableException extends OauthSsoErrorLoggableException { | ||
constructor(private readonly errorCode?: string) { | ||
super(errorCode ?? 'sso_auth_code_step', 'Authorization Query Object has no authorization code or error'); | ||
} | ||
|
||
override getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { | ||
return { | ||
type: 'SSO_AUTH_CODE_STEP', | ||
message: 'Authorization Query Object has no authorization code or error', | ||
stack: this.stack, | ||
data: { | ||
errorCode: this.errorCode, | ||
}, | ||
}; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../server/src/modules/oauth/loggable/id-token-extraction-failure-loggable-exception.spec.ts
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { IdTokenExtractionFailureLoggableException } from './id-token-extraction-failure-loggable-exception'; | ||
|
||
describe(IdTokenExtractionFailureLoggableException.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const fieldName = 'id_token'; | ||
const exception = new IdTokenExtractionFailureLoggableException(fieldName); | ||
return { exception, fieldName }; | ||
}; | ||
|
||
it('should return a LogMessage', () => { | ||
const { exception, fieldName } = setup(); | ||
|
||
const logMessage = exception.getLogMessage(); | ||
|
||
expect(logMessage).toEqual({ | ||
type: 'SSO_JWT_PROBLEM', | ||
message: 'Failed to extract field', | ||
stack: exception.stack, | ||
data: { | ||
fieldName, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
apps/server/src/modules/oauth/loggable/id-token-extraction-failure-loggable-exception.ts
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ErrorLogMessage, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; | ||
import { OauthSsoErrorLoggableException } from './oauth-sso-error-loggable-exception'; | ||
|
||
export class IdTokenExtractionFailureLoggableException extends OauthSsoErrorLoggableException { | ||
constructor(private readonly fieldName: string) { | ||
super(); | ||
} | ||
|
||
override getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { | ||
return { | ||
type: 'SSO_JWT_PROBLEM', | ||
message: 'Failed to extract field', | ||
stack: this.stack, | ||
data: { | ||
fieldName: this.fieldName, | ||
}, | ||
}; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
apps/server/src/modules/oauth/loggable/id-token-invalid-loggable-exception.spec.ts
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { IdTokenInvalidLoggableException } from './id-token-invalid-loggable-exception'; | ||
|
||
describe(IdTokenInvalidLoggableException.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const exception = new IdTokenInvalidLoggableException(); | ||
return { exception }; | ||
}; | ||
|
||
it('should return a LogMessage', () => { | ||
const { exception } = setup(); | ||
|
||
const logMessage = exception.getLogMessage(); | ||
|
||
expect(logMessage).toEqual({ | ||
type: 'SSO_JWT_PROBLEM', | ||
message: 'Failed to validate idToken', | ||
stack: expect.any(String), | ||
}); | ||
}); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
apps/server/src/modules/oauth/loggable/id-token-invalid-loggable-exception.ts
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ErrorLogMessage, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; | ||
import { OauthSsoErrorLoggableException } from './oauth-sso-error-loggable-exception'; | ||
|
||
export class IdTokenInvalidLoggableException extends OauthSsoErrorLoggableException { | ||
override getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { | ||
return { | ||
type: 'SSO_JWT_PROBLEM', | ||
message: 'Failed to validate idToken', | ||
stack: this.stack, | ||
}; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
apps/server/src/modules/oauth/loggable/id-token-user-not-found-loggable-exception.spec.ts
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { IdTokenUserNotFoundLoggableException } from './id-token-user-not-found-loggable-exception'; | ||
|
||
describe(IdTokenUserNotFoundLoggableException.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const uuid = 'uuid'; | ||
const additionalInfo = 'additionalInfo'; | ||
|
||
const exception = new IdTokenUserNotFoundLoggableException(uuid, additionalInfo); | ||
|
||
return { | ||
exception, | ||
uuid, | ||
additionalInfo, | ||
}; | ||
}; | ||
|
||
it('should return a LogMessage', () => { | ||
const { exception, uuid, additionalInfo } = setup(); | ||
|
||
const logMessage = exception.getLogMessage(); | ||
|
||
expect(logMessage).toEqual({ | ||
type: 'SSO_USER_NOTFOUND', | ||
message: 'Failed to find user with uuid from id token', | ||
stack: exception.stack, | ||
data: { | ||
uuid, | ||
additionalInfo, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
apps/server/src/modules/oauth/loggable/id-token-user-not-found-loggable-exception.ts
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ErrorLogMessage, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; | ||
import { OauthSsoErrorLoggableException } from './oauth-sso-error-loggable-exception'; | ||
|
||
export class IdTokenUserNotFoundLoggableException extends OauthSsoErrorLoggableException { | ||
constructor(private readonly uuid: string, private readonly additionalInfo?: string) { | ||
super(); | ||
} | ||
|
||
override getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { | ||
return { | ||
type: 'SSO_USER_NOTFOUND', | ||
message: 'Failed to find user with uuid from id token', | ||
stack: this.stack, | ||
data: { | ||
uuid: this.uuid, | ||
additionalInfo: this.additionalInfo, | ||
}, | ||
}; | ||
} | ||
} |
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,4 +1,8 @@ | ||
export * from './oauth-sso.error'; | ||
export * from './sso-error-code.enum'; | ||
export * from './user-not-found-after-provisioning.loggable-exception'; | ||
export * from './token-request-loggable-exception'; | ||
export { OauthSsoErrorLoggableException } from './oauth-sso-error-loggable-exception'; | ||
export { AuthCodeFailureLoggableException } from './auth-code-failure-loggable-exception'; | ||
export { IdTokenInvalidLoggableException } from './id-token-invalid-loggable-exception'; | ||
export { OauthConfigMissingLoggableException } from './oauth-config-missing-loggable-exception'; | ||
export { IdTokenExtractionFailureLoggableException } from './id-token-extraction-failure-loggable-exception'; | ||
export { IdTokenUserNotFoundLoggableException } from './id-token-user-not-found-loggable-exception'; |
31 changes: 31 additions & 0 deletions
31
apps/server/src/modules/oauth/loggable/oauth-config-missing-loggable-exception.spec.ts
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ObjectId } from 'bson'; | ||
import { OauthConfigMissingLoggableException } from './oauth-config-missing-loggable-exception'; | ||
|
||
describe(OauthConfigMissingLoggableException.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const systemId = new ObjectId().toHexString(); | ||
const exception = new OauthConfigMissingLoggableException(systemId); | ||
|
||
return { | ||
exception, | ||
systemId, | ||
}; | ||
}; | ||
|
||
it('should return a LogMessage', () => { | ||
const { exception, systemId } = setup(); | ||
|
||
const logMessage = exception.getLogMessage(); | ||
|
||
expect(logMessage).toEqual({ | ||
type: 'SSO_INTERNAL_ERROR', | ||
message: 'Requested system has no oauth configured', | ||
stack: exception.stack, | ||
data: { | ||
systemId, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
apps/server/src/modules/oauth/loggable/oauth-config-missing-loggable-exception.ts
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ErrorLogMessage, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; | ||
import { OauthSsoErrorLoggableException } from './oauth-sso-error-loggable-exception'; | ||
|
||
export class OauthConfigMissingLoggableException extends OauthSsoErrorLoggableException { | ||
constructor(private readonly systemId: string) { | ||
super(); | ||
} | ||
|
||
override getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { | ||
return { | ||
type: 'SSO_INTERNAL_ERROR', | ||
message: 'Requested system has no oauth configured', | ||
stack: this.stack, | ||
data: { | ||
systemId: this.systemId, | ||
}, | ||
}; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
apps/server/src/modules/oauth/loggable/oauth-sso-error-loggable-exception.spec.ts
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { OauthSsoErrorLoggableException } from './oauth-sso-error-loggable-exception'; | ||
|
||
describe(OauthSsoErrorLoggableException.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const exception = new OauthSsoErrorLoggableException(); | ||
|
||
return { | ||
exception, | ||
}; | ||
}; | ||
|
||
it('should return a LogMessage', () => { | ||
const { exception } = setup(); | ||
|
||
const result = exception.getLogMessage(); | ||
|
||
expect(result).toEqual({ | ||
type: 'SSO_LOGIN_FAILED', | ||
message: 'Internal Server Error', | ||
stack: expect.any(String), | ||
}); | ||
}); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
apps/server/src/modules/oauth/loggable/oauth-sso-error-loggable-exception.ts
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { InternalServerErrorException } from '@nestjs/common'; | ||
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; | ||
|
||
export class OauthSsoErrorLoggableException extends InternalServerErrorException implements Loggable { | ||
getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { | ||
return { | ||
type: 'SSO_LOGIN_FAILED', | ||
message: this.message, | ||
stack: this.stack, | ||
}; | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
apps/server/src/modules/oauth/loggable/oauth-sso.error.spec.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
apps/server/src/modules/oauth/loggable/sso-error-code.enum.ts
This file was deleted.
Oops, something went wrong.
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.