Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration tests for policy api okta 288650 #151

Merged
merged 3 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/it/mocks/group.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"profile": {
"name": "Application delete group"
"name": "Mock Group"
}
}
47 changes: 47 additions & 0 deletions test/it/mocks/okta-sign-on-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"type": "OKTA_SIGN_ON",
"name": "Mock Policy",
"description": "mock policy for testing",
"conditions": {
"people": {
"groups": {
"include": []
}
}
},
"_links": {
"self": {
"hints": {
"allow": [
"GET",
"PUT",
"DELETE"
]
}
},
"active": {
"hints": {
"allow": [
"POST"
]
}
},
"deactivate": {
"hints": {
"allow": [
"POST"
]
}
},
"rules": {
"hints": {
"allow": [
"GET",
"POST",
"PUT",
"DELETE"
]
}
}
}
}
18 changes: 18 additions & 0 deletions test/it/mocks/policy-deny-rule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "SIGN_ON",
"name": "Mock deny rule",
"conditions": {
"network": {
"connection": "ANYWHERE"
},
"authContext": {
"authType": "ANY"
}
},
"actions": {
"signon": {
"access": "DENY",
"requireFactor": false
}
}
}
126 changes: 126 additions & 0 deletions test/it/policy-crud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
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 mockGroup = require('./mocks/group.json');
const mockOktaSignOnPolicy = require('./mocks/okta-sign-on-policy.json');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

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

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

describe('Policy Crud API', () => {
let group;
let mockPolicy;
beforeEach(async () => {
group = await client.createGroup(mockGroup);
mockPolicy = deepcopy(mockOktaSignOnPolicy);
mockPolicy.conditions.people.groups.include.push(group.id);
});
afterEach(async () => {
await group.delete();
});

describe('List policies', () => {
let policy;
beforeEach(async () => {
policy = await client.createPolicy(mockPolicy);
});
afterEach(async () => {
await policy.delete();
});

it('should return a Collection', async () => {
const policies = await client.listPolicies({ type: 'OKTA_SIGN_ON' });
expect(policies).to.be.instanceOf(Collection);
});

it('should resolve Policy in collection', async () => {
await client.listPolicies({ type: 'OKTA_SIGN_ON' }).each(policy => {
expect(policy).to.be.instanceOf(models.Policy);
});
});

it('should return a collection of policies by type', async () => {
await client.listPolicies({ type: 'OKTA_SIGN_ON' }).each(policy => {
expect(policy.type).to.equal('OKTA_SIGN_ON');
});
});
});

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

it('should return correct model', async () => {
policy = await client.createPolicy(mockPolicy);
expect(policy).to.be.instanceOf(models.Policy);
});

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

describe('Get policy', () => {
let policy;
beforeEach(async () => {
policy = await client.createPolicy(mockPolicy);
});
afterEach(async () => {
await policy.delete();
});

it('should get Policy by id', async () => {
const policyFromGet = await client.getPolicy(policy.id);
expect(policyFromGet).to.be.instanceOf(models.Policy);
expect(policyFromGet.name).to.equal(mockPolicy.name);
});
});

describe('Update policy', () => {
let policy;
beforeEach(async () => {
policy = await client.createPolicy(mockPolicy);
});
afterEach(async () => {
await policy.delete();
});

it('should update name for policy', async () => {
const mockName = 'Mock update policy';
policy.name = mockName;
const updatedPolicy = await policy.update();
expect(updatedPolicy.id).to.equal(policy.id);
expect(updatedPolicy.name).to.equal(mockName);
});
});

describe('Delete policy', () => {
let policy;
beforeEach(async () => {
policy = await client.createPolicy(mockPolicy);
});

it('should not get policy after deletion', async () => {
await policy.delete();
try {
await client.getPolicy(policy.id);
} catch (e) {
expect(e.status).to.equal(404);
}
});
});
});
42 changes: 42 additions & 0 deletions test/it/policy-lifecycle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const expect = require('chai').expect;
const deepcopy = require('deep-copy');
const okta = require('../../src');
const mockGroup = require('./mocks/group.json');
const mockOktaSignOnPolicy = require('./mocks/okta-sign-on-policy.json');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

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

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

describe('Policy Lifecycle API', () => {
let group;
let mockPolicy;
let policy;
beforeEach(async () => {
group = await client.createGroup(mockGroup);
mockPolicy = deepcopy(mockOktaSignOnPolicy);
mockPolicy.conditions.people.groups.include.push(group.id);
policy = await client.createPolicy(mockPolicy);
});
afterEach(async () => {
await policy.delete();
await group.delete();
});

it('should activate policy', async () => {
const response = await policy.activate();
expect(response.status).to.equal(204);
});

it('should deactive policy', async () => {
const response = await policy.deactivate();
expect(response.status).to.equal(204);
});
});
146 changes: 146 additions & 0 deletions test/it/policy-rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
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 mockGroup = require('./mocks/group.json');
const mockOktaSignOnPolicy = require('./mocks/okta-sign-on-policy.json');
const mockRule = require('./mocks/policy-deny-rule.json');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;

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

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

describe('Policy Rule API', () => {
let group;
let mockPolicy;
let policy;
beforeEach(async () => {
group = await client.createGroup(mockGroup);
mockPolicy = deepcopy(mockOktaSignOnPolicy);
mockPolicy.conditions.people.groups.include.push(group.id);
policy = await client.createPolicy(mockPolicy);
});
afterEach(async () => {
await policy.delete();
await group.delete();
});

describe('Policy rule crud', () => {
describe('List rules', () => {
let rule;
beforeEach(async () => {
rule = await policy.createRule(mockRule);
});
afterEach(async () => {
await rule.delete(policy.id);
});

it('should return a Collection', async () => {
const rules = await policy.listPolicyRules();
expect(rules).to.be.instanceOf(Collection);
});

it('should resolve PolicyRule in collection', async () => {
await policy.listPolicyRules().each(rule => {
expect(rule).to.be.instanceOf(models.PolicyRule);
});
});
});

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

it('should return correct model', async () => {
rule = await policy.createRule(mockRule);
expect(rule).to.be.instanceOf(models.PolicyRule);
});

it('should return correct data with id assigned', async () => {
rule = await policy.createRule(mockRule);
expect(rule).to.have.property('id');
expect(rule.name).to.equal(mockRule.name);
});
});

describe('Get rule', () => {
let rule;
beforeEach(async () => {
rule = await policy.createRule(mockRule);
});
afterEach(async () => {
await rule.delete(policy.id);
});

it('should get PolicyRule by id', async () => {
const ruleFromGet = await client.getPolicyRule(policy.id, rule.id);
expect(ruleFromGet).to.be.instanceOf(models.PolicyRule);
expect(ruleFromGet.name).to.equal(mockRule.name);
});
});

describe('Update rule', () => {
let rule;
beforeEach(async () => {
rule = await policy.createRule(mockRule);
});
afterEach(async () => {
await rule.delete(policy.id);
});

it('should update name for policy rule', async () => {
const mockName = 'Mock update policy rule';
rule.name = mockName;
const updatedPolicyRule = await rule.update(policy.id);
expect(updatedPolicyRule.id).to.equal(rule.id);
expect(updatedPolicyRule.name).to.equal(mockName);
});
});

describe('Delete rule', () => {
let rule;
beforeEach(async () => {
rule = await policy.createRule(mockRule);
});

it('should not get rule after deletion', async () => {
await rule.delete(policy.id);
try {
await policy.getPolicyRule(rule.id);
} catch (e) {
expect(e.status).to.equal(404);
}
});
});
});

describe('Policy rule lifecycle', () => {
let rule;
beforeEach(async () => {
rule = await policy.createRule(mockRule);
});
afterEach(async () => {
await rule.delete(policy.id);
});

it('should activate rule', async () => {
const response = await rule.activate(policy.id);
expect(response.status).to.equal(204);
});

it('should deactive rule', async () => {
const response = await rule.deactivate(policy.id);
expect(response.status).to.equal(204);
});
});
});