Skip to content

Commit

Permalink
test(security): add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jannyHou committed Aug 20, 2019
1 parent f2ca26e commit 770dd5a
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 20 deletions.
7 changes: 0 additions & 7 deletions packages/security/docs.json

This file was deleted.

8 changes: 7 additions & 1 deletion packages/security/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions packages/security/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "@loopback/security",
"version": "0.1.0",
"version": "0.0.1",
"description": "A LoopBack component for security support.",
"engines": {
"node": ">=8.9"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"acceptance": "lb-mocha \"dist/__tests__/acceptance/**/*.js\"",
"build": "lb-tsc",
"build:apidocs": "lb-apidocs",
"clean": "lb-clean loopback-security*.tgz dist package api-docs",
"clean": "lb-clean loopback-security*.tgz dist package *.tsbuildinfo",
"integration": "lb-mocha \"dist/__tests__/integration/**/*.js\"",
"prepublishOnly": "npm run build && npm run build:apidocs",
"pretest": "npm run build",
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
"unit": "lb-mocha \"dist/__tests__/unit/**/*.js\"",
Expand All @@ -21,14 +22,15 @@
"copyright.owner": "IBM Corp.",
"license": "MIT",
"dependencies": {
"@loopback/context": "^1.13.0",
"@loopback/context": "^1.21.4",
"@loopback/core": "^1.9.3",
"debug": "^4.1.1"
},
"devDependencies": {
"@loopback/build": "^1.5.2",
"@loopback/testlab": "^1.2.7",
"@loopback/build": "^2.0.8",
"@loopback/testlab": "^1.7.4",
"@types/debug": "^4.1.4",
"casbin": "^2.0.4"
"@types/node": "^10.14.15"
},
"keywords": [
"LoopBack",
Expand All @@ -44,6 +46,7 @@
],
"repository": {
"type": "git",
"url": "https://github.com/strongloop/loopback-next.git"
"url": "https://github.com/strongloop/loopback-next.git",
"directory": "packages/security"
}
}
15 changes: 15 additions & 0 deletions packages/security/src/__tests__/unit/principle.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/security
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';
import {Principal, securityId, TypedPrincipal} from '../..';

describe('typed principle', () => {
it('returns the security id', () => {
const principal: Principal = {[securityId]: 'auser'};
const typedPrincipal = new TypedPrincipal(principal, 'USER');
expect(typedPrincipal[securityId]).to.eql('USER:auser');
});
});
36 changes: 34 additions & 2 deletions packages/security/src/__tests__/unit/subject.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,45 @@
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';
import {DefaultSubject, securityId, UserProfile} from '../..';
import {
ClientApplication,
DefaultSubject,
securityId,
UserProfile,
} from '../..';
import {Permission} from '../../types';

describe('DefaultSubject', () => {
const subject = new DefaultSubject();
it('adds users', () => {
const subject = new DefaultSubject();
const user: UserProfile = {[securityId]: 'user-001', type: 'USER'};
subject.addUser(user);
expect(subject.user).to.eql(user);
});

it('adds application', () => {
const app: ClientApplication = {
[securityId]: 'app-001',
type: 'APPLICATION',
};
subject.addApplication(app);
expect(subject.getPrincipal('APPLICATION')).to.equal(app);
});

it('adds authority', () => {
const perm1 = new Permission();
perm1.action = 'get';
perm1.resourceType = 'User';
const perm2 = new Permission();
perm2.action = 'update';
perm2.resourceType = 'User';
subject.addAuthority(perm1, perm2);
expect(subject.authorities).to.containEql(perm1);
expect(subject.authorities).to.containEql(perm2);
});
it('adds credential', () => {
const cred = {usr: 'auser', pass: 'mypass'};
subject.addCredential(cred);
expect(subject.credentials).to.containEql(cred);
});
});
1 change: 0 additions & 1 deletion packages/security/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
},
"include": ["src"]
}

0 comments on commit 770dd5a

Please sign in to comment.