Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed adding a Gitlab app via UI #1146

Merged
merged 1 commit into from
Nov 30, 2021
Merged

Fixed adding a Gitlab app via UI #1146

merged 1 commit into from
Nov 30, 2021

Conversation

josecordaz
Copy link
Contributor

Closes:

What changed?
Interpret integer as seconds

Why?
It was interpreting the integer as milliseconds instead of seconds, causing unauthorized errors as the token only had a few seconds of validity.

How did you test it?
I manually added an app via UI, getting the next message afterwards:
image

Release notes

Documentation Changes

@josecordaz josecordaz added bug Something isn't working type/enhancement New feature or request and removed bug Something isn't working labels Nov 30, 2021
@josecordaz josecordaz marked this pull request as ready for review November 30, 2021 01:30
Copy link
Contributor

@jpellizzari jpellizzari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

Edit: Nit: can we add some test coverage? Like maybe we should validate that the expiration is what we expect it to be

Copy link
Contributor

@palemtnrider palemtnrider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Minor nit on the fix.
+1 on adding a test(s)

@@ -633,7 +633,7 @@ func (s *applicationServer) AuthorizeGitlab(ctx context.Context, msg *pb.Authori
return nil, fmt.Errorf("could not exchange code: %w", err)
}

token, err := s.jwtClient.GenerateJWT(time.Duration(tokenState.ExpiresIn), gitproviders.GitProviderGitLab, tokenState.AccessToken)
token, err := s.jwtClient.GenerateJWT(time.Duration(tokenState.ExpiresIn)*time.Second, gitproviders.GitProviderGitLab, tokenState.AccessToken)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit but multiplying by seconds here makes the code a bit obscure. From looking at the code it appears that only GitLab (today) uses the ExpiresIn field. However, others might. The code is more readable (to me) if we add a function on tokenState to return the expires value in seconds - or another field ExpiresInSeconds. Then the individual providers can provide the conversion - if necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the type assertion time.Duration either, because multiplying an integer by time.Duration will get you a time.Duration.

@josecordaz josecordaz merged commit 6866ff9 into main Nov 30, 2021
@josecordaz josecordaz deleted the fix-add-gitlab-ui branch November 30, 2021 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants