Skip to content

Commit 4d742f6

Browse files
committed
chore: improve AD error messages and fix failing test
1 parent ac5851d commit 4d742f6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/service/passport/activeDirectory.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ const configure = (passport) => {
4343
const message = `User it not a member of ${userGroup}`;
4444
return done(message, null);
4545
}
46-
} catch (e) {
47-
const message = `An error occurred while checking if the user is a member of the user group: ${JSON.stringify(e)}`;
46+
} catch (err) {
47+
console.log('ad test (isUser): e', err);
48+
const message = `An error occurred while checking if the user is a member of the user group: ${err.message}`;
4849
return done(message, null);
4950
}
5051

@@ -53,9 +54,9 @@ const configure = (passport) => {
5354
try {
5455
isAdmin = await ldaphelper.isUserInAdGroup(req, profile, ad, domain, adminGroup);
5556

56-
} catch (e) {
57-
const message = `An error occurred while checking if the user is a member of the admin group: ${JSON.stringify(e)}`;
58-
console.error(message, e); // don't return an error for this case as you may still be a user
57+
} catch (err) {
58+
const message = `An error occurred while checking if the user is a member of the admin group: ${err.message}`;
59+
console.error(message, err); // don't return an error for this case as you may still be a user
5960
}
6061

6162
profile.admin = isAdmin;

test/testActiveDirectoryAuth.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('ActiveDirectory auth method', () => {
144144

145145
expect(done.calledOnce).to.be.true;
146146
const [err, user] = done.firstCall.args;
147-
expect(err.message).to.equal('LDAP error');
147+
expect(err).to.contain('LDAP error');
148148
expect(user).to.be.null;
149149
});
150150
});

0 commit comments

Comments
 (0)