-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
71 additions
and
52 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
|
@@ -22,15 +22,13 @@ describe('storage ldap', () => { | |
await storage._createOrganization({ id: 'myorg', name: 'My Org' }) | ||
await storage._createUser({ | ||
id: 'alban1', | ||
name: 'Alban Mouton', | ||
firstName: 'Alban', | ||
lastName: 'Mouton', | ||
email: '[email protected]', | ||
organizations: [{ id: 'myorg', role: 'admin', name: 'my org' }] | ||
}) | ||
await storage._createUser({ | ||
id: 'test1', | ||
name: 'Test User', | ||
firstName: 'Test', | ||
lastName: 'User', | ||
email: '[email protected]', | ||
|
@@ -63,7 +61,7 @@ describe('storage ldap', () => { | |
|
||
const members = await storage.findMembers('myorg', { skip: 0, size: 10 }) | ||
assert.equal(members.count, 2) | ||
assert.equal(members.results[0].name, 'Alban Mouton') | ||
assert.equal(members.results[0].name, 'alban1') | ||
assert.equal(members.results[0].role, 'overwritten') | ||
|
||
const members2 = await storage.findMembers('myorg', { q: 'notauser', skip: 0, size: 10 }) | ||
|
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 |
---|---|---|
|
@@ -53,7 +53,7 @@ describe('ldap storage per organization in file storage mode', () => { | |
assert.equal(res.data.count, 1) | ||
assert.equal(res.data.results[0].email, '[email protected]') | ||
assert.equal(res.data.results[0].orgStorage, true) | ||
assert.equal(res.data.results[0].id, 'ldap_test-ldap_Alban Mouton') | ||
assert.equal(res.data.results[0].id, 'ldap_test-ldap_alban') | ||
|
||
// TODO: add auth test with user password | ||
}) | ||
|
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 |
---|---|---|
|
@@ -21,16 +21,9 @@ describe('ldap storage API', () => { | |
firstName: 'Alban', | ||
lastName: 'Mouton', | ||
email: '[email protected]', | ||
organizations: [{ id: 'myorg', role: 'admin', name: 'my org' }], | ||
organizations: [{ id: 'myorg', role: 'user', name: 'my org' }], | ||
password: 'passwd' | ||
}) | ||
await storage._createUser({ | ||
id: 'alban2', | ||
firstName: 'Alban', | ||
lastName: '', | ||
email: '[email protected]', | ||
organizations: [{ id: 'myorg', role: 'user', name: 'my org' }] | ||
}) | ||
}) | ||
|
||
after(stopApiServer) | ||
|
@@ -49,6 +42,6 @@ describe('ldap storage API', () => { | |
const res = await ax.get('/api/auth/me') | ||
assert.equal(res.status, 200) | ||
assert.equal(res.data.id, 'alban') | ||
console.log('ME', res.data) | ||
assert.equal(res.data.organizations?.[0].id, 'myorg') | ||
}) | ||
}) |
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,24 +1,64 @@ | ||
import { strict as assert } from 'node:assert' | ||
import { it, describe, before, beforeEach, after } from 'node:test' | ||
import { clean, startApiServer, stopApiServer, createUser } from './utils/index.ts' | ||
import { axiosAuth, clean, startApiServer, stopApiServer, createUser } from './utils/index.ts' | ||
import type { LdapStorage } from '../api/src/storages/ldap.ts' | ||
|
||
process.env.STORAGE_TYPE = 'mongo' | ||
process.env.NODE_CONFIG_DIR = 'api/config/' | ||
const config = (await import('../api/src/config.ts')).default | ||
const ldapConfig = JSON.parse(JSON.stringify(config.storage.ldap)) | ||
ldapConfig.organizations.staticSingleOrg = { id: 'test-single-org', name: 'Test single org' } | ||
ldapConfig.members.role.values = { admin: ['administrator'], user: [] } | ||
|
||
describe.only('ldap storage per organization in mongodb storage mode', () => { | ||
const orgLdapConfig = { | ||
url: 'ldap://localhost:389', | ||
baseDN: 'dc=example,dc=org', | ||
searchUserDN: 'cn=admin,dc=example,dc=org', | ||
searchUserPassword: 'admin', | ||
users: { | ||
objectClass: 'inetOrgPerson', | ||
dnKey: 'cn', | ||
mapping: { | ||
id: 'cn', | ||
name: 'cn', | ||
email: 'mail', | ||
firstName: 'givenName', | ||
lastName: 'sn' | ||
}, | ||
extraFilters: ['sn=Mouton'] | ||
} | ||
} | ||
|
||
describe('ldap storage per organization in mongodb storage mode', () => { | ||
before(startApiServer) | ||
beforeEach(async () => await clean({ ldapConfig })) | ||
after(stopApiServer) | ||
|
||
it.only('create a user and organization and configure orgStorage with ldap config', async () => { | ||
const { ax, user } = await createUser('test1@test.com') | ||
it('create a user and organization and configure orgStorage with ldap config', async () => { | ||
const { ax: axAdmin, user } = await createUser('admin@test.com', true) | ||
assert.ok(user.id) | ||
const org = (await ax.post('/api/organizations', { name: 'Org 1' })).data | ||
console.log(org) | ||
const org = (await axAdmin.post('/api/organizations', { name: 'Org 1' })).data | ||
assert.ok(org.id) | ||
const patchedOrg = (await axAdmin.patch(`/api/organizations/${org.id}`, { | ||
orgStorage: { | ||
type: 'ldap', | ||
active: true, | ||
config: orgLdapConfig | ||
} | ||
})).data | ||
|
||
const storage = (await (await import('../api/src/storages/index.ts')).default.createOrgStorage(patchedOrg)) as LdapStorage | ||
await storage._createUser({ | ||
id: 'alban', | ||
firstName: 'Alban', | ||
lastName: 'Mouton', | ||
email: '[email protected]', | ||
organizations: [{ id: org.id, role: 'user', name: 'Org 1' }], | ||
password: 'passwd' | ||
}) | ||
|
||
const ax = await axiosAuth({ email: '[email protected]', org: org.id, orgStorage: true }) | ||
const res = await ax.get('/api/auth/me') | ||
assert.equal(res.status, 200) | ||
assert.ok(res.data.id.endsWith('_alban')) | ||
assert.equal(res.data.organizations?.[0].id, org.id) | ||
}) | ||
}) |