-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle comma separated allowed roles (#391)
* fix: Fix issue where hasura-auth crashes when adding allowed roles upon signin with provider * chore: Run prettier * chore: Update .changeset/strange-seas-whisper.md Co-authored-by: Szilárd Dóró <[email protected]> --------- Co-authored-by: Szilárd Dóró <[email protected]>
- Loading branch information
1 parent
fe87694
commit 0cc9d36
Showing
4 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'hasura-auth': patch | ||
--- | ||
|
||
fix: don't crash when adding allowed roles upon sign-in with a provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,51 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`OAuth helpers should handle an array of allowed roles 1`] = ` | ||
Object { | ||
"avatarUrl": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1234567890123456&height=50&width=50&ext=1234567894&hash=Qdiofewu-OPO", | ||
"defaultRole": "user", | ||
"displayName": "Bob Smith", | ||
"email": "[email protected]", | ||
"emailVerified": false, | ||
"locale": "en", | ||
"metadata": Object {}, | ||
"passwordHash": null, | ||
"roles": Object { | ||
"data": Array [ | ||
Object { | ||
"role": "user", | ||
}, | ||
Object { | ||
"role": "me", | ||
}, | ||
], | ||
}, | ||
} | ||
`; | ||
|
||
exports[`OAuth helpers should handle comma separated allowedRoles 1`] = ` | ||
Object { | ||
"avatarUrl": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1234567890123456&height=50&width=50&ext=1234567894&hash=Qdiofewu-OPO", | ||
"defaultRole": "user", | ||
"displayName": "Bob Smith", | ||
"email": "[email protected]", | ||
"emailVerified": false, | ||
"locale": "en", | ||
"metadata": Object {}, | ||
"passwordHash": null, | ||
"roles": Object { | ||
"data": Array [ | ||
Object { | ||
"role": "user", | ||
}, | ||
Object { | ||
"role": "me", | ||
}, | ||
], | ||
}, | ||
} | ||
`; | ||
|
||
exports[`OAuth helpers should transform a Facebook profile 1`] = ` | ||
Object { | ||
"avatarUrl": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1234567890123456&height=50&width=50&ext=1234567894&hash=Qdiofewu-OPO", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,4 +86,50 @@ describe('OAuth helpers', () => { | |
const output = await transformOauthProfile(normalisedProfile); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
it('should handle an array of allowed roles', async () => { | ||
const facebookProfile = { | ||
id: '1234567890123456', | ||
name: 'Bob Smith', | ||
email: '[email protected]', | ||
picture: { | ||
data: { | ||
height: 50, | ||
is_silhouette: false, | ||
url: 'https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1234567890123456&height=50&width=50&ext=1234567894&hash=Qdiofewu-OPO', | ||
width: 50, | ||
}, | ||
}, | ||
}; | ||
const normalisedProfile = await normaliseProfile('facebook', { | ||
profile: facebookProfile, | ||
}); | ||
const output = await transformOauthProfile(normalisedProfile, { | ||
allowedRoles: ['user', 'me'], | ||
}); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
it('should handle comma separated allowedRoles', async () => { | ||
const facebookProfile = { | ||
id: '1234567890123456', | ||
name: 'Bob Smith', | ||
email: '[email protected]', | ||
picture: { | ||
data: { | ||
height: 50, | ||
is_silhouette: false, | ||
url: 'https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1234567890123456&height=50&width=50&ext=1234567894&hash=Qdiofewu-OPO', | ||
width: 50, | ||
}, | ||
}, | ||
}; | ||
const normalisedProfile = await normaliseProfile('facebook', { | ||
profile: facebookProfile, | ||
}); | ||
const output = await transformOauthProfile(normalisedProfile, { | ||
allowedRoles: 'user,me' as any, | ||
}); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
}); |