-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add it for admin role - OKTA-288641 (#158)
* test: add it for admin role - OKTA-288641 * test: update test with openapi updates
- Loading branch information
Showing
10 changed files
with
257 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*! | ||
* Copyright (c) 2017-2020, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
|
||
/* THIS FILE IS AUTO-GENERATED - SEE CONTRIBUTOR DOCUMENTATION */ | ||
|
||
var UserFactor = require('./UserFactor'); | ||
const WebAuthnUserFactorProfile = require('./WebAuthnUserFactorProfile'); | ||
|
||
/** | ||
* @class WebAuthnUserFactor | ||
* @extends UserFactor | ||
* @property { WebAuthnUserFactorProfile } profile | ||
*/ | ||
class WebAuthnUserFactor extends UserFactor { | ||
constructor(resourceJson, client) { | ||
super(resourceJson, client); | ||
if (resourceJson && resourceJson.profile) { | ||
this.profile = new WebAuthnUserFactorProfile(resourceJson.profile); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = WebAuthnUserFactor; |
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,33 @@ | ||
/*! | ||
* Copyright (c) 2017-2020, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
|
||
/* THIS FILE IS AUTO-GENERATED - SEE CONTRIBUTOR DOCUMENTATION */ | ||
|
||
var Resource = require('../resource'); | ||
|
||
|
||
/** | ||
* @class WebAuthnUserFactorProfile | ||
* @extends Resource | ||
* @property { string } authenticatorName | ||
* @property { string } credentialId | ||
*/ | ||
class WebAuthnUserFactorProfile extends Resource { | ||
constructor(resourceJson, client) { | ||
super(resourceJson, client); | ||
|
||
} | ||
|
||
} | ||
|
||
module.exports = WebAuthnUserFactorProfile; |
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,35 @@ | ||
const expect = require('chai').expect; | ||
const okta = require('../../src'); | ||
const models = require('../../src/models'); | ||
const mockGroup = require('./mocks/group.json'); | ||
let orgUrl = process.env.OKTA_CLIENT_ORGURL; | ||
|
||
if (process.env.OKTA_USE_MOCK) { | ||
orgUrl = `${orgUrl}/group-role`; | ||
} | ||
|
||
const client = new okta.Client({ | ||
orgUrl: orgUrl, | ||
token: process.env.OKTA_CLIENT_TOKEN, | ||
requestExecutor: new okta.DefaultRequestExecutor() | ||
}); | ||
|
||
describe('Group role API', () => { | ||
describe('Role assignment', () => { | ||
let group; | ||
beforeEach(async () => { | ||
group = await client.createGroup(mockGroup); | ||
}); | ||
afterEach(async () => { | ||
await group.delete(); | ||
}); | ||
|
||
it('should assign and unassign role to/from group', async () => { | ||
const role = await group.assignRole({ type: 'APP_ADMIN' }); | ||
expect(role).to.be.instanceOf(models.Role); | ||
|
||
const res = await client.removeRoleFromGroup(group.id, role.id); | ||
expect(res.status).to.equal(204); | ||
}); | ||
}); | ||
}); |
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,145 @@ | ||
const expect = require('chai').expect; | ||
const okta = require('../../src'); | ||
const models = require('../../src/models'); | ||
const Collection = require('../../src/collection'); | ||
const mockGroup = require('./mocks/group.json'); | ||
const mockUser = require('./mocks/user-without-credentials.json'); | ||
const utils = require('../utils'); | ||
let orgUrl = process.env.OKTA_CLIENT_ORGURL; | ||
|
||
if (process.env.OKTA_USE_MOCK) { | ||
orgUrl = `${orgUrl}/user-role`; | ||
} | ||
|
||
const client = new okta.Client({ | ||
orgUrl: orgUrl, | ||
token: process.env.OKTA_CLIENT_TOKEN, | ||
requestExecutor: new okta.DefaultRequestExecutor() | ||
}); | ||
|
||
describe('User role API', () => { | ||
let user; | ||
beforeEach(async () => { | ||
user = await client.createUser(mockUser, { activate: false }); | ||
}); | ||
afterEach(async () => { | ||
await utils.cleanupUser(client, user); | ||
}); | ||
|
||
describe('Role assignment', () => { | ||
let role; | ||
afterEach(async () => { | ||
user.removeRole(role.id); | ||
}); | ||
|
||
it('should assign role to user', async () => { | ||
role = await user.assignRole({ type: 'APP_ADMIN' }); | ||
expect(role).to.be.instanceOf(models.Role); | ||
expect(role.id).to.be.exist; | ||
expect(role.type).to.equal('APP_ADMIN'); | ||
}); | ||
}); | ||
|
||
describe('Role unassignment', () => { | ||
let role; | ||
beforeEach(async () => { | ||
role = await user.assignRole({ type: 'APP_ADMIN' }); | ||
}); | ||
|
||
it('should unassign role from user', async () => { | ||
const res = await user.removeRole(role.id); | ||
expect(res.status).to.equal(204); | ||
}); | ||
}); | ||
|
||
describe('List user assigned roles', () => { | ||
let role; | ||
beforeEach(async () => { | ||
role = await user.assignRole({ type: 'APP_ADMIN' }); | ||
}); | ||
afterEach(async () => { | ||
user.removeRole(role.id); | ||
}); | ||
|
||
it('should return a Collection of roles', async () => { | ||
const roles = await user.listAssignedRoles(); | ||
expect(roles).to.be.instanceOf(Collection); | ||
await roles.each(roleFromCollection => { | ||
expect(roleFromCollection).to.be.instanceOf(models.Role); | ||
expect(roleFromCollection.id).to.be.equal(role.id); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('App targets for admin role', () => { | ||
let role; | ||
let application; | ||
beforeEach(async () => { | ||
role = await user.assignRole({ type: 'APP_ADMIN' }); | ||
const mockApplication = utils.getBookmarkApplication(); | ||
application = await client.createApplication(mockApplication); | ||
}); | ||
afterEach(async () => { | ||
await application.deactivate(); | ||
await application.delete(); | ||
await user.removeRole(role.id); | ||
}); | ||
|
||
describe('Add app target', () => { | ||
it('should add app target to admin user', async () => { | ||
const res = await role.addAppTargetToAdminRoleForUser(user.id, application.name); | ||
expect(res.status).to.equal(204); | ||
}); | ||
}); | ||
|
||
describe('List app targets', () => { | ||
beforeEach(async () => { | ||
await role.addAppTargetToAdminRoleForUser(user.id, application.name); | ||
}); | ||
|
||
it('should return a Collection of CatalogApplications', async () => { | ||
const apps = await client.listApplicationTargetsForApplicationAdministratorRoleForUser(user.id, role.id); | ||
expect(apps).to.be.instanceOf(Collection); | ||
await apps.each(app => { | ||
expect(app).to.be.instanceOf(models.CatalogApplication); | ||
expect(app.name).to.be.equal(application.name); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Group targets for admin role', () => { | ||
let role; | ||
let group; | ||
beforeEach(async () => { | ||
role = await user.assignRole({ type: 'USER_ADMIN' }); | ||
group = await client.createGroup(mockGroup); | ||
}); | ||
afterEach(async () => { | ||
await user.removeRole(role.id); | ||
await group.delete(); | ||
}); | ||
|
||
describe('Add group target', () => { | ||
it('should add group target to admin user', async () => { | ||
const res = await user.addGroupTarget(role.id, group.id); | ||
expect(res.status).to.equal(204); | ||
}); | ||
}); | ||
|
||
describe('List group targets', () => { | ||
beforeEach(async () => { | ||
await user.addGroupTarget(role.id, group.id); | ||
}); | ||
|
||
it('should return a Collection of Groups', async () => { | ||
const groups = await client.listApplicationTargetsForApplicationAdministratorRoleForUser(user.id, role.id); | ||
expect(groups).to.be.instanceOf(Collection); | ||
await groups.each(groupFromCollection => { | ||
expect(groupFromCollection).to.be.instanceOf(models.Group); | ||
expect(groupFromCollection.id).to.be.equal(group.id); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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