-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: panics in oauth providers (#374)
We were just checking each item in the slice of interfaces if they were nil. The interface points to the data of the encapsulated type and an itable. Checking if the item is nil, does not actually check if the data encapsulated by the interface is nil, so the previous check wasn't doing what we actually wanted. Instead we can modify the existing interface to add a `Provided() bool` to check if the data is actually nil or not. This should prevent the previous panic and issues with OAuth not working.
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
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
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,45 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/utils/ptr" | ||
) | ||
|
||
type oauthProvider interface { | ||
Provided() bool | ||
} | ||
|
||
func TestOAuthCommonProvided(t *testing.T) { | ||
oauth := EndpointOAuth{} | ||
|
||
providers := []oauthProvider{ | ||
oauth.Amazon, | ||
oauth.Facebook, | ||
oauth.Github, | ||
oauth.Gitlab, | ||
oauth.Google, | ||
oauth.Linkedin, | ||
oauth.Microsoft, | ||
oauth.Twitch, | ||
} | ||
|
||
// When no provider config is present, all should return false for Provided() | ||
for _, p := range providers { | ||
assert.False(t, p.Provided()) | ||
} | ||
|
||
microsoft := &EndpointOAuthMicrosoft{} | ||
microsoft.ClientID = ptr.To("a") | ||
|
||
oauth = EndpointOAuth{ | ||
Microsoft: microsoft, | ||
} | ||
// When a provider is present, it should return true for Provided() and ones | ||
// that are not provided should return false. | ||
assert.True(t, oauth.Microsoft.Provided()) | ||
assert.False(t, oauth.Google.Provided()) | ||
assert.False(t, oauth.Twitch.Provided()) | ||
assert.False(t, oauth.Github.Provided()) | ||
} |
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