-
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 application - OKTA-288642
- Loading branch information
Showing
3 changed files
with
160 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
const expect = require('chai').expect; | ||
const okta = require('../../'); | ||
const models = require('../../src/models'); | ||
const Collection = require('../../src/collection'); | ||
const mockApplication = require('./mocks/application-oidc.json'); | ||
|
||
let orgUrl = process.env.OKTA_CLIENT_ORGURL; | ||
|
||
if (process.env.OKTA_USE_MOCK) { | ||
orgUrl = `${orgUrl}/application-grant`; | ||
} | ||
|
||
const client = new okta.Client({ | ||
orgUrl: orgUrl, | ||
token: process.env.OKTA_CLIENT_TOKEN, | ||
requestExecutor: new okta.DefaultRequestExecutor() | ||
}); | ||
|
||
describe('Application OAuth2 grant API', () => { | ||
let application; | ||
let grant; | ||
beforeEach(async () => { | ||
application = await client.createApplication(mockApplication); | ||
}); | ||
afterEach(async () => { | ||
await application.deactivate(); | ||
await application.delete(); | ||
}); | ||
|
||
describe('Grant consent', () => { | ||
it('should grant consent to scope', async () => { | ||
grant = await application.grantConsentToScope({ | ||
issuer: client.baseUrl, | ||
scopeId: 'okta.users.manage' | ||
}); | ||
expect(grant).to.be.instanceOf(models.OAuth2ScopeConsentGrant); | ||
expect(grant.issuer).to.equal(client.baseUrl); | ||
}); | ||
}); | ||
|
||
describe('List scope consent grants', () => { | ||
beforeEach(async () => { | ||
grant = await application.grantConsentToScope({ | ||
issuer: client.baseUrl, | ||
scopeId: 'okta.users.manage' | ||
}); | ||
}); | ||
afterEach(async () => { | ||
await application.revokeScopeConsentGrant(grant.id); | ||
}); | ||
|
||
it('should return a collection of OAuth2ScopeConsentGrant', async () => { | ||
const grants = await application.listScopeConsentGrants({ | ||
applicationId: application.id | ||
}); | ||
expect(grants).to.be.instanceOf(Collection); | ||
await grants.each(grantFromCollection => { | ||
expect(grantFromCollection).to.be.instanceOf(models.OAuth2ScopeConsentGrant); | ||
expect(grantFromCollection.id).to.equal(grant.id); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Get scope consent grant', () => { | ||
beforeEach(async () => { | ||
grant = await application.grantConsentToScope({ | ||
issuer: client.baseUrl, | ||
scopeId: 'okta.users.manage' | ||
}); | ||
}); | ||
afterEach(async () => { | ||
await application.revokeScopeConsentGrant(grant.id); | ||
}); | ||
|
||
it('should get grant by id', async () => { | ||
const grantFromGet = await application.getScopeConsentGrant(grant.id); | ||
expect(grantFromGet).to.be.exist; | ||
expect(grantFromGet).to.be.instanceOf(models.OAuth2ScopeConsentGrant); | ||
}); | ||
}); | ||
|
||
describe('Revoke grant', () => { | ||
beforeEach(async () => { | ||
grant = await application.grantConsentToScope({ | ||
issuer: client.baseUrl, | ||
scopeId: 'okta.users.manage' | ||
}); | ||
}); | ||
|
||
it('should revoke grant', async () => { | ||
const res = await application.revokeScopeConsentGrant(grant.id); | ||
expect(res.status).to.equal(204); | ||
try { | ||
await application.getScopeConsentGrant(grant.id); | ||
} catch (err) { | ||
expect(err.status).to.equal(404); | ||
} | ||
}); | ||
}); | ||
}); |
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,41 @@ | ||
const expect = require('chai').expect; | ||
const okta = require('../../'); | ||
const Collection = require('../../src/collection'); | ||
const mockApplication = require('./mocks/application-oidc.json'); | ||
|
||
let orgUrl = process.env.OKTA_CLIENT_ORGURL; | ||
|
||
if (process.env.OKTA_USE_MOCK) { | ||
orgUrl = `${orgUrl}/application-token`; | ||
} | ||
|
||
const client = new okta.Client({ | ||
orgUrl: orgUrl, | ||
token: process.env.OKTA_CLIENT_TOKEN, | ||
requestExecutor: new okta.DefaultRequestExecutor() | ||
}); | ||
|
||
// As there is no way to create oauth2 token in test env | ||
// Only test if list and revoke tokens endpoints get triggered and proper response get returned | ||
describe('Application OAuth2 token API', () => { | ||
let application; | ||
beforeEach(async () => { | ||
application = await client.createApplication(mockApplication); | ||
}); | ||
afterEach(async () => { | ||
await application.deactivate(); | ||
await application.delete(); | ||
}); | ||
|
||
it('should list a collection of tokens', async () => { | ||
const grants = await application.listOAuth2Tokens(); | ||
expect(grants).to.be.instanceOf(Collection); | ||
const res = await grants.getNextPage(); | ||
expect(res).to.be.an('array').that.is.empty; | ||
}); | ||
|
||
it('should return status 204 when revoke tokens for application', async () => { | ||
const res = await application.revokeOAuth2Tokens(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "oidc_client", | ||
"label": "MOCK_CLIENT_CRED", | ||
"signOnMode": "OPENID_CONNECT", | ||
"settings": { | ||
"oauthClient": { | ||
"redirect_uris": [ | ||
"https://example.com" | ||
], | ||
"response_types": [ | ||
"code" | ||
], | ||
"grant_types": [ | ||
"authorization_code" | ||
], | ||
"application_type": "native" | ||
} | ||
} | ||
} |