Skip to content

added fetching groups of user if the scope includes 'api', extended and refactored tests - #14

Open
zergar wants to merge 3 commits into
fh1ch:masterfrom
zergar:master
Open

added fetching groups of user if the scope includes 'api', extended and refactored tests#14
zergar wants to merge 3 commits into
fh1ch:masterfrom
zergar:master

Conversation

@zergar

@zergar zergar commented Dec 17, 2019

Copy link
Copy Markdown

Description

This commit includes changes that extend the profile-object returned by this application to include the groups the user has access to. This is done by means of a nested callback which is executed if the scope includes 'api'. The callback extends the profile object by the groups-property, which value is an array containing the group names.

To test the behaviour of the newly added code, the strategy.profile.spec.js was extended with more tests. It was necessary to wrap the _oauth.get-method inside a closure to generate different behaviour, as this class mocks the behaviour of that method. The oAuthGetReplacementClosure now accepts a config object to e.g. return a malformed response to the groups request, but a correct one to the profile-request. The existing tests were adapted to use the newly introduced method.

Further information

This feature is useful if an existing gitlab-deployment shall be used for login, but not every user should have access to the application. To my knowledge, there exists no standardized way for writing groups to the user profile. Therefore, this commit uses the most basic approach of just adding the groups as an array of strings.

…nd refactored tests

This commit includes changes that extend the profile-object returned by this application to include the groups the user has access to. This is done by means of a nested callback which is executed if the scope includes 'api'. The callback extends the profile object by the `groups`-property, which value is an array containing the group names.

To test the behaviour of the newly added code, the strategy.profile.spec.js was extended with more tests. It was necessary to wrap the _oauth.get-method inside a closure to generate different behaviour, as this class mocks the behaviour of that method. The oAuthGetReplacementClosure now accepts a config object to e.g. return a malformed response to the groups request, but a correct one to the profile-request. The existing tests were adapted to use the newly introduced method.

Signed-off-by: Gereon Dusella <git@gereondusella.de>
Signed-off-by: Gereon Dusella <git@gereondusella.de>
the strategy.spec.js missed the query parameter which limits the administrator from being included in all groups.

Signed-off-by: Gereon Dusella <git@gereondusella.de>
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling 7d4457a on zergar:master into 4238b67 on fh1ch:master.

@andmagom

andmagom commented Aug 1, 2022

Copy link
Copy Markdown

Hello @fh1ch, how are you ? The passport-gitlab2 module, is it still maintained ? Do you think, you can merge this MR to the module ? I'm looking for a way to filter logins based on the group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants