Skip to content

Commit 9f752da

Browse files
committed
test: ad auth admin
1 parent 5e4216e commit 9f752da

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/testActiveDirectoryAuth.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,36 @@ describe('ActiveDirectory auth method', () => {
6363
configure(passportStub);
6464
});
6565

66+
it('should authenticate a valid user and mark them as admin', async () => {
67+
const mockReq = {};
68+
const mockProfile = {
69+
_json: {
70+
sAMAccountName: 'test-user',
71+
72+
userPrincipalName: '[email protected]',
73+
title: 'Test User',
74+
},
75+
displayName: 'Test User',
76+
};
77+
78+
ldapStub.isUserInAdGroup
79+
.onCall(0).resolves(true)
80+
.onCall(1).resolves(true);
81+
82+
const done = sinon.spy();
83+
84+
await strategyCallback(mockReq, mockProfile, {}, done);
85+
86+
expect(done.calledOnce).to.be.true;
87+
const [err, user] = done.firstCall.args;
88+
expect(err).to.be.null;
89+
expect(user).to.have.property('username', 'test-user');
90+
expect(user).to.have.property('email', '[email protected]');
91+
expect(user).to.have.property('displayName', 'Test User');
92+
expect(user).to.have.property('admin', true);
93+
expect(user).to.have.property('title', 'Test User');
94+
95+
expect(dbStub.updateUser.calledOnce).to.be.true;
96+
});
97+
6698
});

0 commit comments

Comments
 (0)