Skip to content

Commit

Permalink
add integration tests for idp okta 288649 (#150)
Browse files Browse the repository at this point in the history
* test: add idp-crud it

* test: it for idp-user operations

* test: refactor idp-crub to use model methods

* refactor: remove commented code in idp-user

* test: it for idp-lifecycle

* test: add list social tokens test for idp-user

* test: it for idp-credential

* fix: remove only and counter

* test: add more assertions for key test suite
  • Loading branch information
shuowu authored May 20, 2020
1 parent 3607910 commit 3d8003c
Show file tree
Hide file tree
Showing 8 changed files with 592 additions and 0 deletions.
217 changes: 217 additions & 0 deletions test/it/idp-credential.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
const expect = require('chai').expect;
const deepcopy = require('deep-copy');
const okta = require('../../src');
const models = require('../../src/models');
const Collection = require('../../src/collection');
const mockGenericOidcIdp = require('./mocks/generic-oidc-idp.json');
const mockJwk = require('./mocks/jwk.json');
const mockCsr = require('./mocks/csr.json');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

if (process.env.OKTA_USE_MOCK) {
orgUrl = `${orgUrl}/idp-user`;
}

const client = new okta.Client({
orgUrl: orgUrl,
token: process.env.OKTA_CLIENT_TOKEN,
requestExecutor: new okta.DefaultRequestExecutor()
});

describe('Idp Lifecycle API', () => {
let idp;
beforeEach(async () => {
idp = await client.createIdentityProvider(mockGenericOidcIdp);
});

afterEach(async () => {
await idp.delete();
});

describe('Key', () => {
let key;
describe('List keys', () => {
beforeEach(async () => {
key = await client.createIdentityProviderKey(mockJwk);
});
afterEach(async () => {
await client.deleteIdentityProviderKey(key.kid);
});

it('should return a Collection', async () => {
const keys = client.listIdentityProviderKeys();
expect(keys).to.be.instanceOf(Collection);
});

it('should resolve JsonWebKey in collection', async () => {
await client.listIdentityProviderKeys().each(key => {
expect(key).to.be.instanceOf(models.JsonWebKey);
});
});
});

describe('Create key', () => {
afterEach(async () => {
await client.deleteIdentityProviderKey(key.kid);
});

it('should create key', async () => {
key = await client.createIdentityProviderKey(mockJwk);
expect(key).to.be.exist;
expect(key).to.be.instanceOf(models.JsonWebKey);
});
});

describe('Get key', () => {
beforeEach(async () => {
key = await client.createIdentityProviderKey(mockJwk);
});
afterEach(async () => {
await client.deleteIdentityProviderKey(key.kid);
});

it('should get key', async () => {
key = await client.getIdentityProviderKey(key.kid);
expect(key).to.be.exist;
expect(key).to.be.instanceOf(models.JsonWebKey);
});
});

describe('Delete key', () => {
beforeEach(async () => {
key = await client.createIdentityProviderKey(mockJwk);
});

it('should delete key', async () => {
await client.deleteIdentityProviderKey(key.kid);
try {
await client.getIdentityProviderKey(key.kid);
} catch (e) {
expect(e.status).to.equal(404);
}
});
});
});

describe('Signing CSR', () => {
let csr;
describe('List signing csrs', () => {
beforeEach(async () => {
csr = await idp.generateCsr(mockCsr);
});
afterEach(async () => {
await idp.deleteSigningCsr(csr.id);
});

it('should return a Collection', async () => {
const csrs = idp.listSigningCsrs();
expect(csrs).to.be.instanceOf(Collection);
});

it('should resolve CSR in collection', async () => {
await idp.listSigningCsrs().each(csr => {
expect(csr).to.be.instanceOf(models.CSR);
});
});
});

describe('Generate signing csr', () => {
afterEach(async () => {
await idp.deleteSigningCsr(csr.id);
});

it('should generate csr', async () => {
csr = await idp.generateCsr(mockCsr);
expect(csr).to.be.exist;
});
});

describe('Delete signing csr', () => {
beforeEach(async () => {
csr = await idp.generateCsr(mockCsr);
});

it('should delete csr', async () => {
await idp.deleteSigningCsr(csr.id);
try {
csr = await idp.getSigningCsr(csr.id);
} catch (e) {
expect(e.status).to.equal(404);
}
});
});

describe('Get csr', () => {
beforeEach(async () => {
csr = await idp.generateCsr(mockCsr);
});
afterEach(async () => {
await idp.deleteSigningCsr(csr.id);
});

it('should get csr', async () => {
csr = await idp.getSigningCsr(csr.id);
expect(csr).to.be.exist;
});
});
});

describe('Signing Key', () => {
let key;
describe('List signing keys', () => {
beforeEach(async () => {
key = await idp.generateSigningKey({ validityYears: 2 });
});

it('should return a Collection', async () => {
const keys = await idp.listSigningKeys();
expect(keys).to.be.instanceOf(Collection);
});

it('should resolve JsonWebKey in collection', async () => {
await idp.listSigningKeys().each(key => {
expect(key).to.be.instanceOf(models.JsonWebKey);
});
});

});

describe('Generate signing keys', () => {
it('should generate csr', async () => {
key = await idp.generateCsr(mockCsr);
expect(key).to.be.exist;
});
});

describe('Get signing keys', () => {
beforeEach(async () => {
key = await idp.generateSigningKey({ validityYears: 2 });
});

it('should return a Collection', async () => {
key = await idp.getSigningKey(key.kid);
expect(key).to.be.exist;
});
});

describe('Clone key', () => {
let anotherIdp;
beforeEach(async () => {
const anotherMockGenericOidcIdp = deepcopy(mockGenericOidcIdp);
anotherMockGenericOidcIdp.name = 'Another Mock OpenID Connect IdP';
anotherIdp = await client.createIdentityProvider(anotherMockGenericOidcIdp);
key = await idp.generateSigningKey({ validityYears: 2 });
});

afterEach(async () => {
await anotherIdp.delete();
});

it('should clone key to another idp', async () => {
const clonedKey = await idp.cloneKey(key.kid, { targetIdpId: anotherIdp.id });
expect(clonedKey).to.be.exist;
expect(clonedKey).to.be.instanceOf(models.JsonWebKey);
});
});
});
});
123 changes: 123 additions & 0 deletions test/it/idp-crud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
const expect = require('chai').expect;
const okta = require('../../src');
const models = require('../../src/models');
const Collection = require('../../src/collection');
const mockGenericOidcIdp = require('./mocks/generic-oidc-idp.json');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

if (process.env.OKTA_USE_MOCK) {
orgUrl = `${orgUrl}/idp-crud`;
}

const client = new okta.Client({
orgUrl: orgUrl,
token: process.env.OKTA_CLIENT_TOKEN,
requestExecutor: new okta.DefaultRequestExecutor()
});

describe('Idp Crud API', () => {
describe('List idps', () => {
let idp;
beforeEach(async () => {
idp = await client.createIdentityProvider(mockGenericOidcIdp);
});

afterEach(async () => {
await idp.delete();
});

it('should return a Collection', async () => {
const idps = await client.listIdentityProviders();
expect(idps).to.be.instanceOf(Collection);
});

it('should resolve IdentityProvider in collection', async () => {
await client.listIdentityProviders().each(idp => {
expect(idp).to.be.instanceOf(models.IdentityProvider);
});
});

it('should return a collection of idp by type', async () => {
await client.listIdentityProviders({ type: 'OIDC' }).each(idp => {
expect(idp.type).to.equal('OIDC');
});
});

it('should return a collection of idp by q', async () => {
await client.listIdentityProviders({ q: 'OIDC' }).each(idp => {
expect(idp.type).to.equal('OIDC');
});
});
});

describe('Create idp', () => {
let idp;
afterEach(async () => {
await idp.delete();
});

it('should return correct model', async () => {
idp = await client.createIdentityProvider(mockGenericOidcIdp);
expect(idp).to.be.instanceOf(models.IdentityProvider);
});

it('should return correct data with id assigned', async () => {
idp = await client.createIdentityProvider(mockGenericOidcIdp);
expect(idp).to.have.property('id');
expect(idp.name).to.equal(mockGenericOidcIdp.name);
});
});

describe('Get idp', () => {
let idp;
beforeEach(async () => {
idp = await client.createIdentityProvider(mockGenericOidcIdp);
});

afterEach(async () => {
await idp.delete();
});

it('should get IdentityProvider by id', async () => {
const idpFromGet = await client.getIdentityProvider(idp.id);
expect(idpFromGet).to.be.instanceOf(models.IdentityProvider);
expect(idpFromGet.name).to.equal(mockGenericOidcIdp.name);
});
});

describe('Update idp', () => {
let idp;
let updatedIdp;
beforeEach(async () => {
idp = await client.createIdentityProvider(mockGenericOidcIdp);
});

afterEach(async () => {
await idp.delete();
});

it('should update all properties in template', async () => {
const mockName = 'Mock update idp';
idp.name = mockName;
updatedIdp = await idp.update();
expect(updatedIdp.id).to.equal(idp.id);
expect(updatedIdp.name).to.equal(mockName);
});
});

describe('Delete idp', () => {
let idp;
beforeEach(async () => {
idp = await client.createIdentityProvider(mockGenericOidcIdp);
});

it('should not get idp after deletion', async () => {
await idp.delete();
try {
await client.getIdentityProvider(idp.id);
} catch (e) {
expect(e.status).to.equal(404);
}
});
});
});
35 changes: 35 additions & 0 deletions test/it/idp-lifecycle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const expect = require('chai').expect;
const okta = require('../../src');
const mockGenericOidcIdp = require('./mocks/generic-oidc-idp.json');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

if (process.env.OKTA_USE_MOCK) {
orgUrl = `${orgUrl}/idp-user`;
}

const client = new okta.Client({
orgUrl: orgUrl,
token: process.env.OKTA_CLIENT_TOKEN,
requestExecutor: new okta.DefaultRequestExecutor()
});

describe('Idp Lifecycle API', () => {
let idp;
beforeEach(async () => {
idp = await client.createIdentityProvider(mockGenericOidcIdp);
});

afterEach(async () => {
await idp.delete();
});

it('should activate idp', async () => {
idp = await idp.activate();
expect(idp.status).to.equal('ACTIVE');
});

it('should deactive idp', async () => {
idp = await idp.deactivate();
expect(idp.status).to.equal('INACTIVE');
});
});
Loading

0 comments on commit 3d8003c

Please sign in to comment.