-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: release branch [ci skip] (#116) * feat: update readme and launch&tasks.json files for keycloak operator * feat: rm unnecessary lines from launch.json and package.json * feat: add createTeamUser in the keycloak operator * feat: update groups * feat: update create user * feat: update harbor operator * feat: update create user * feat: add delete keycloak users function * test: delete keycloak users * feat: update create keycloak user * feat: update keycloak user without credentials * test: update user * feat: update keycloak createUpdateUser * feat: update keycloak.ts * test: users * feat: keycloak userCreateUpdate * feat: update user creation * feat: update keycloak manageUsers flow * feat: update keycloak.ts and add keycloak.test.ts * feat: update manageUsers * feat: update existing otomi-admin user groups * fix: update platformAdminUser variable name --------- Co-authored-by: Ani Argjiri <[email protected]>
- Loading branch information
1 parent
2c39535
commit d086529
Showing
11 changed files
with
331 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"camelcase", | ||
"creds", | ||
"gitea", | ||
"keycloak", | ||
"kubernetes", | ||
"oidc", | ||
"openid", | ||
|
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { expect } from 'chai' | ||
import sinon from 'sinon' | ||
import { addUserGroups, removeUserGroups } from './keycloak' | ||
|
||
describe('Keycloak User Group Management', () => { | ||
let api: any | ||
let existingUser: any | ||
let keycloakRealm: string | ||
|
||
beforeEach(() => { | ||
keycloakRealm = 'otomi' | ||
existingUser = { id: 'user-id' } | ||
api = { | ||
users: { | ||
realmUsersIdGroupsGet: sinon.stub(), | ||
realmUsersIdGroupsGroupIdDelete: sinon.stub(), | ||
realmUsersIdGroupsGroupIdPut: sinon.stub(), | ||
}, | ||
groups: { | ||
realmGroupsGet: sinon.stub(), | ||
}, | ||
} | ||
}) | ||
|
||
afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
describe('removeUserGroups', () => { | ||
it('should remove user from groups not in teamGroups', async () => { | ||
const existingUserGroups = [ | ||
{ name: 'group1', id: 'group1-id' }, | ||
{ name: 'group2', id: 'group2-id' }, | ||
] | ||
api.users.realmUsersIdGroupsGet.resolves({ body: existingUserGroups }) | ||
|
||
await removeUserGroups(api, existingUser, ['group1']) | ||
|
||
expect(api.users.realmUsersIdGroupsGroupIdDelete.calledWith(keycloakRealm, 'user-id', 'group2-id')).to.be.true | ||
expect(api.users.realmUsersIdGroupsGroupIdDelete.calledWith(keycloakRealm, 'user-id', 'group1-id')).to.be.false | ||
}) | ||
|
||
it('should handle errors gracefully', async () => { | ||
api.users.realmUsersIdGroupsGet.rejects(new Error('API Error')) | ||
|
||
await removeUserGroups(api, existingUser, ['group1']) | ||
|
||
expect(api.users.realmUsersIdGroupsGroupIdDelete.called).to.be.false | ||
}) | ||
}) | ||
|
||
describe('addUserGroups', () => { | ||
it('should add user to groups in teamGroups if not already present', async () => { | ||
const currentKeycloakGroups = [ | ||
{ name: 'group1', id: 'group1-id' }, | ||
{ name: 'group2', id: 'group2-id' }, | ||
] | ||
const existingUserGroups = [{ name: 'group1', id: 'group1-id' }] | ||
api.groups.realmGroupsGet.resolves({ body: currentKeycloakGroups }) | ||
api.users.realmUsersIdGroupsGet.resolves({ body: existingUserGroups }) | ||
|
||
await addUserGroups(api, existingUser, ['group1', 'group2']) | ||
|
||
expect(api.users.realmUsersIdGroupsGroupIdPut.calledWith(keycloakRealm, 'user-id', 'group2-id')).to.be.true | ||
expect(api.users.realmUsersIdGroupsGroupIdPut.calledWith(keycloakRealm, 'user-id', 'group1-id')).to.be.false | ||
}) | ||
|
||
it('should handle errors gracefully', async () => { | ||
api.groups.realmGroupsGet.rejects(new Error('API Error')) | ||
|
||
await addUserGroups(api, existingUser, ['group1']) | ||
|
||
expect(api.users.realmUsersIdGroupsGroupIdPut.called).to.be.false | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.