-
-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement multi token support for client tokens
This adds support for multi project tokens to be created. Backward compatibility is handled at 3 different layers here: - The API is made backwards compatible though a permissive data type that accepts either a project?: string or projects?: string[] property, validation is done through JOI here, which ensures that projects and project are not set together. In the case of neither, this defaults to the previous default of ALL_PROJECTS - The service layer method to handle adding tokens has been made tolerant to either of the above case and has been deprecated, a new method supporting only the new structure of using projects has been added - Existing compatibility for consumers of Unleash as a library should not be affected either, the ApiUser constructor is now tolerant to the the first input and will internally map to the new cleaned structure
- Loading branch information
Showing
15 changed files
with
410 additions
and
54 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
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,44 @@ | ||
import { ALL } from '../types/models/api-token'; | ||
import { createApiToken } from './api-token-schema'; | ||
|
||
test('should reject token with projects and project', async () => { | ||
expect.assertions(1); | ||
try { | ||
await createApiToken.validateAsync({ | ||
username: 'test', | ||
type: 'admin', | ||
project: 'default', | ||
projects: ['default'], | ||
}); | ||
} catch (error) { | ||
expect(error.details[0].message).toEqual( | ||
'"project" must not exist simultaneously with [projects]', | ||
); | ||
} | ||
}); | ||
|
||
test('should not have default project set if projects is present', async () => { | ||
let token = await createApiToken.validateAsync({ | ||
username: 'test', | ||
type: 'admin', | ||
projects: ['default'], | ||
}); | ||
expect(token.project).not.toBeDefined(); | ||
}); | ||
|
||
test('should have project set to default if projects is missing', async () => { | ||
let token = await createApiToken.validateAsync({ | ||
username: 'test', | ||
type: 'admin', | ||
}); | ||
expect(token.project).toBe(ALL); | ||
}); | ||
|
||
test('should not have projects set if project is present', async () => { | ||
let token = await createApiToken.validateAsync({ | ||
username: 'test', | ||
type: 'admin', | ||
project: 'default', | ||
}); | ||
expect(token.projects).not.toBeDefined(); | ||
}); |
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.