Skip to content

Commit 44caede

Browse files
authored
Merge pull request #533 from bheesham/allow-different-apps-to-define-multiple-groups
fix(access): allow apps to be defined multiple times
2 parents aba9e15 + 07c045e commit 44caede

3 files changed

Lines changed: 53 additions & 12 deletions

File tree

tf/actions/accessRules.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,27 +267,25 @@ exports.onExecutePostLogin = async (event, api) => {
267267
app.authorized_users.length > 0 &&
268268
app.authorized_users.indexOf(event.user.email) >= 0
269269
) {
270-
authorized = true;
270+
authorized ||= true;
271271
// Same dance as above, but for groups
272272
} else if (
273273
app.authorized_groups.length > 0 &&
274274
hasCommonElements(app.authorized_groups, groups)
275275
) {
276-
authorized = true;
277-
} else {
278-
authorized = false;
279-
}
280-
281-
if (!authorized) {
282-
const msg =
283-
`Access denied to ${event.client.client_id} for user ${event.user.email} (${event.user.user_id})` +
284-
` - not in authorized group or not an authorized user`;
285-
console.log(msg);
286-
return deny("notingroup");
276+
authorized ||= true;
287277
}
288278
} // correct client id / we matched the current RP
289279
} // for loop / next rule in apps.yml
290280

281+
if (!authorized) {
282+
const msg =
283+
`Access denied to ${event.client.client_id} for user ${event.user.email} (${event.user.user_id})` +
284+
` - not in authorized group or not an authorized user`;
285+
console.log(msg);
286+
return deny("notingroup");
287+
}
288+
291289
// AAI (AUTHENTICATOR ASSURANCE INDICATOR)
292290
// Sets the AAI for the user. This is later used by the AccessRules.js rule which also sets the AAL.
293291

tf/tests/accessRules.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,3 +625,36 @@ describe("Client is defined in apps.yml as client00000000000000000000000008", ()
625625
);
626626
});
627627
});
628+
629+
describe("Client is defined multiple times in apps.yml as client00000000000000000000000009", () => {
630+
test("User in restricted_group_1; expect allowed", async () => {
631+
_event.client.client_id = "client00000000000000000000000009";
632+
_event.connection.name = "google-oauth2";
633+
_event.user.groups = ["restricted_group_1"];
634+
_event.user.ldap_groups = [];
635+
_event.user.app_metadata.groups = [];
636+
await onExecutePostLogin(_event, api);
637+
expect(_event.transaction.redirect_uri).toEqual(undefined);
638+
});
639+
test("User in restricted_group_2; expect allowed", async () => {
640+
_event.client.client_id = "client00000000000000000000000009";
641+
_event.connection.name = "google-oauth2";
642+
_event.user.groups = ["restricted_group_2"];
643+
_event.user.ldap_groups = [];
644+
_event.user.app_metadata.groups = [];
645+
await onExecutePostLogin(_event, api);
646+
expect(_event.transaction.redirect_uri).toEqual(undefined);
647+
});
648+
test("User in restricted_group_3; expect denied", async () => {
649+
_event.client.client_id = "client00000000000000000000000009";
650+
_event.connection.name = "google-oauth2";
651+
_event.user.groups = ["restricted_group_3"];
652+
_event.user.ldap_groups = [];
653+
_event.user.app_metadata.groups = [];
654+
await onExecutePostLogin(_event, api);
655+
expect(_event.transaction.redirect_uri).toBeDefined();
656+
expect(decodeRedirect(_event.transaction.redirect_uri)).toEqual(
657+
"notingroup"
658+
);
659+
});
660+
});

tf/tests/modules/apps.yml.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ apps:
6262
- team_moco
6363
- team_mofo
6464
authorized_users: []
65+
- application:
66+
authorized_groups:
67+
- restricted_group_1
68+
authorized_users: []
69+
client_id: client00000000000000000000000009
70+
- application:
71+
authorized_groups:
72+
- restricted_group_2
73+
authorized_users: []
74+
client_id: client00000000000000000000000009
6575
`;
6676
return appsYaml;
6777
},

0 commit comments

Comments
 (0)