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

feat: validate access token #308

Merged
merged 5 commits into from
May 29, 2024
Merged

feat: validate access token #308

merged 5 commits into from
May 29, 2024

Conversation

dbolson
Copy link
Contributor

@dbolson dbolson commented May 28, 2024

When setting the access token in the config, check if it works by making an API request. If it's unauthorized, don't write to the config and tell the user.

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Provide links to any issues in this repository or elsewhere relating to this pull request.

Describe the solution you've provided

Provide a clear and concise description of what you expect to happen.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the pull request here.

@@ -38,10 +39,10 @@ func (cmd ConfigCmd) HelpCalled() bool {
return cmd.helpCalled
}

func NewConfigCmd(analyticsTrackerFn analytics.TrackerFn) *ConfigCmd {
func NewConfigCmd(service config.Service, analyticsTrackerFn analytics.TrackerFn) *ConfigCmd {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pass in the service so we can mock its HTTP client in tests.

}

// VerifyAccessToken is true if the given access token is valid to make API requests.
func (s Service) VerifyAccessToken(accessToken string, baseURI string) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could move more of the config --set code into the config domain if it would make the cmd more readable.

@@ -16,5 +21,9 @@ func (c *MockClient) MakeRequest(
) ([]byte, error) {
c.Input = data

if c.StatusCode > http.StatusBadRequest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this for stubbing the HTTP client response.

@dbolson dbolson requested a review from k3llymariee May 28, 2024 22:10
@dbolson dbolson merged commit 5591a0a into main May 29, 2024
2 checks passed
@dbolson dbolson deleted the sc-241909/validate-access-token branch May 29, 2024 17:07
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.

2 participants