-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add default value for cookie TTL (#456)
- Loading branch information
Showing
6 changed files
with
71 additions
and
4 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
6 changes: 6 additions & 0 deletions
6
.../src/constants/authentication.contants.ts → ...src/constants/authentication.constants.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
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 +1 @@ | ||
export * from './authentication.contants'; | ||
export * from './authentication.constants'; |
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
53 changes: 53 additions & 0 deletions
53
libs/nestjs/authentication/src/dtos/authentication-options-cookies.dto.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,53 @@ | ||
import { AuthenticationOptionsCookies } from './authentication-options-cookies.dto'; | ||
|
||
import { transformAndValidate } from '@tractr/common'; | ||
|
||
describe('AuthenticationOptionsCookies', () => { | ||
it('should pass if config is valid', () => { | ||
const config = { | ||
cookieName: 'authCookie', | ||
options: { | ||
httpOnly: true, | ||
maxAge: 86400000, | ||
secure: false, | ||
}, | ||
queryParamName: 'authToken', | ||
}; | ||
|
||
const validatedDtoWithDefaults = transformAndValidate( | ||
AuthenticationOptionsCookies, | ||
)(config); | ||
|
||
expect(validatedDtoWithDefaults).toEqual(config); | ||
}); | ||
|
||
it('should throw an error if config is not valid', () => { | ||
const config = { | ||
cookieName: 123, | ||
}; | ||
|
||
const validate = transformAndValidate(AuthenticationOptionsCookies); | ||
|
||
expect(() => validate(config)).toThrowError(); | ||
}); | ||
|
||
it('should initialize default values properly', () => { | ||
const config = {}; | ||
|
||
const dtoDefault = { | ||
cookieName: 'authCookie', | ||
options: { | ||
httpOnly: true, | ||
maxAge: 86400000, | ||
secure: false, | ||
}, | ||
queryParamName: 'authToken', | ||
}; | ||
|
||
const validatedDtoWithDefaults = transformAndValidate( | ||
AuthenticationOptionsCookies, | ||
)(config); | ||
|
||
expect(validatedDtoWithDefaults).toEqual(dtoDefault); | ||
}); | ||
}); |
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