Skip to content

Commit

Permalink
fixing nil check for validString check (#96)
Browse files Browse the repository at this point in the history
fixing nil check for validString check
  • Loading branch information
veverkap authored Dec 13, 2019
2 parents 72b0203 + a1c9b3e commit 8b656f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (o OAuthClientCreateOptions) valid() error {
if o.ServiceProvider == nil {
return errors.New("service provider is required")
}
if o.PrivateKey != nil && *o.ServiceProvider != *ServiceProvider(ServiceProviderAzureDevOpsServer) {
if validString(o.PrivateKey) && *o.ServiceProvider != *ServiceProvider(ServiceProviderAzureDevOpsServer) {
return errors.New("Private Key can only be present with Azure DevOps Server service provider")
}
return nil
Expand Down
25 changes: 25 additions & 0 deletions oauth_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,31 @@ func TestOAuthClientsCreateOptionsValid(t *testing.T) {
assert.EqualError(t, err, "service provider is required")
})

t.Run("without private key and not ado_server options", func(t *testing.T) {
options := OAuthClientCreateOptions{
APIURL: String("https://api.github.com"),
HTTPURL: String("https://github.com"),
OAuthToken: String("NOTHING"),
ServiceProvider: ServiceProvider(ServiceProviderGitlabEE),
}

err := options.valid()
assert.Nil(t, err)
})

t.Run("with empty private key and not ado_server options", func(t *testing.T) {
options := OAuthClientCreateOptions{
APIURL: String("https://api.github.com"),
HTTPURL: String("https://github.com"),
OAuthToken: String("NOTHING"),
ServiceProvider: ServiceProvider(ServiceProviderGitlabEE),
PrivateKey: String(""),
}

err := options.valid()
assert.Nil(t, err)
})

t.Run("with private key and not ado_server options", func(t *testing.T) {
options := OAuthClientCreateOptions{
APIURL: String("https://api.github.com"),
Expand Down

0 comments on commit 8b656f1

Please sign in to comment.