-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
subject.unit.ts
48 lines (44 loc) · 1.38 KB
/
subject.unit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 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 {
ClientApplication,
DefaultSubject,
securityId,
UserProfile,
} from '../..';
import {Permission} from '../../types';
describe('DefaultSubject', () => {
const subject = new DefaultSubject();
it('adds users', () => {
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);
});
});