Skip to content

Commit c495d36

Browse files
committed
test: add more ad tests
1 parent 9f752da commit c495d36

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/testActiveDirectoryAuth.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,53 @@ describe('ActiveDirectory auth method', () => {
9595
expect(dbStub.updateUser.calledOnce).to.be.true;
9696
});
9797

98+
it('should fail if user is not in user group', async () => {
99+
const mockReq = {};
100+
const mockProfile = {
101+
_json: {
102+
sAMAccountName: 'bad-user',
103+
104+
userPrincipalName: '[email protected]',
105+
title: 'Bad User'
106+
},
107+
displayName: 'Bad User'
108+
};
109+
110+
ldapStub.isUserInAdGroup.onCall(0).resolves(false);
111+
112+
const done = sinon.spy();
113+
114+
await strategyCallback(mockReq, mockProfile, {}, done);
115+
116+
expect(done.calledOnce).to.be.true;
117+
const [err, user] = done.firstCall.args;
118+
expect(err).to.include('not a member');
119+
expect(user).to.be.null;
120+
121+
expect(dbStub.updateUser.notCalled).to.be.true;
122+
});
123+
124+
it('should handle LDAP errors gracefully', async () => {
125+
const mockReq = {};
126+
const mockProfile = {
127+
_json: {
128+
sAMAccountName: 'error-user',
129+
130+
userPrincipalName: '[email protected]',
131+
title: 'Whoops'
132+
},
133+
displayName: 'Error User'
134+
};
135+
136+
ldapStub.isUserInAdGroup.rejects(new Error('LDAP error'));
137+
138+
const done = sinon.spy();
139+
140+
await strategyCallback(mockReq, mockProfile, {}, done);
141+
142+
expect(done.calledOnce).to.be.true;
143+
const [err, user] = done.firstCall.args;
144+
expect(err.message).to.equal('LDAP error');
145+
expect(user).to.be.null;
146+
});
98147
});

0 commit comments

Comments
 (0)