Fix travis analysis
This commit is contained in:
parent
53524875d1
commit
4eab98e65b
@ -1,15 +1,18 @@
|
|||||||
package providers
|
package providers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pusher/oauth2_proxy/pkg/apis/sessions"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/bmizerany/assert"
|
"github.com/bmizerany/assert"
|
||||||
|
"github.com/pusher/oauth2_proxy/pkg/apis/sessions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const imaginaryAccessToken = "imaginary_access_token"
|
||||||
|
const bearerAccessToken = "Bearer " + imaginaryAccessToken
|
||||||
|
|
||||||
func testKeycloakProvider(hostname, group string) *KeycloakProvider {
|
func testKeycloakProvider(hostname, group string) *KeycloakProvider {
|
||||||
p := NewKeycloakProvider(
|
p := NewKeycloakProvider(
|
||||||
&ProviderData{
|
&ProviderData{
|
||||||
@ -41,7 +44,7 @@ func testKeycloakBackend(payload string) *httptest.Server {
|
|||||||
url := r.URL
|
url := r.URL
|
||||||
if url.Path != path {
|
if url.Path != path {
|
||||||
w.WriteHeader(404)
|
w.WriteHeader(404)
|
||||||
} else if r.Header.Get("Authorization") != "Bearer imaginary_access_token" {
|
} else if r.Header.Get("Authorization") != bearerAccessToken {
|
||||||
w.WriteHeader(403)
|
w.WriteHeader(403)
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
@ -94,10 +97,10 @@ func TestKeycloakProviderGetEmailAddress(t *testing.T) {
|
|||||||
b := testKeycloakBackend("{\"email\": \"michael.bland@gsa.gov\"}")
|
b := testKeycloakBackend("{\"email\": \"michael.bland@gsa.gov\"}")
|
||||||
defer b.Close()
|
defer b.Close()
|
||||||
|
|
||||||
bUrl, _ := url.Parse(b.URL)
|
bURL, _ := url.Parse(b.URL)
|
||||||
p := testKeycloakProvider(bUrl.Host, "")
|
p := testKeycloakProvider(bURL.Host, "")
|
||||||
|
|
||||||
session := &sessions.SessionState{AccessToken: "imaginary_access_token"}
|
session := &sessions.SessionState{AccessToken: imaginaryAccessToken}
|
||||||
email, err := p.GetEmailAddress(session)
|
email, err := p.GetEmailAddress(session)
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, "michael.bland@gsa.gov", email)
|
assert.Equal(t, "michael.bland@gsa.gov", email)
|
||||||
@ -107,10 +110,10 @@ func TestKeycloakProviderGetEmailAddressAndGroup(t *testing.T) {
|
|||||||
b := testKeycloakBackend("{\"email\": \"michael.bland@gsa.gov\", \"groups\": [\"test-grp1\", \"test-grp2\"]}")
|
b := testKeycloakBackend("{\"email\": \"michael.bland@gsa.gov\", \"groups\": [\"test-grp1\", \"test-grp2\"]}")
|
||||||
defer b.Close()
|
defer b.Close()
|
||||||
|
|
||||||
bUrl, _ := url.Parse(b.URL)
|
bURL, _ := url.Parse(b.URL)
|
||||||
p := testKeycloakProvider(bUrl.Host, "test-grp1")
|
p := testKeycloakProvider(bURL.Host, "test-grp1")
|
||||||
|
|
||||||
session := &sessions.SessionState{AccessToken: "imaginary_access_token"}
|
session := &sessions.SessionState{AccessToken: imaginaryAccessToken}
|
||||||
email, err := p.GetEmailAddress(session)
|
email, err := p.GetEmailAddress(session)
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, "michael.bland@gsa.gov", email)
|
assert.Equal(t, "michael.bland@gsa.gov", email)
|
||||||
@ -122,8 +125,8 @@ func TestKeycloakProviderGetEmailAddressFailedRequest(t *testing.T) {
|
|||||||
b := testKeycloakBackend("unused payload")
|
b := testKeycloakBackend("unused payload")
|
||||||
defer b.Close()
|
defer b.Close()
|
||||||
|
|
||||||
bUrl, _ := url.Parse(b.URL)
|
bURL, _ := url.Parse(b.URL)
|
||||||
p := testKeycloakProvider(bUrl.Host, "")
|
p := testKeycloakProvider(bURL.Host, "")
|
||||||
|
|
||||||
// We'll trigger a request failure by using an unexpected access
|
// We'll trigger a request failure by using an unexpected access
|
||||||
// token. Alternatively, we could allow the parsing of the payload as
|
// token. Alternatively, we could allow the parsing of the payload as
|
||||||
@ -138,10 +141,10 @@ func TestKeycloakProviderGetEmailAddressEmailNotPresentInPayload(t *testing.T) {
|
|||||||
b := testKeycloakBackend("{\"foo\": \"bar\"}")
|
b := testKeycloakBackend("{\"foo\": \"bar\"}")
|
||||||
defer b.Close()
|
defer b.Close()
|
||||||
|
|
||||||
bUrl, _ := url.Parse(b.URL)
|
bURL, _ := url.Parse(b.URL)
|
||||||
p := testKeycloakProvider(bUrl.Host, "")
|
p := testKeycloakProvider(bURL.Host, "")
|
||||||
|
|
||||||
session := &sessions.SessionState{AccessToken: "imaginary_access_token"}
|
session := &sessions.SessionState{AccessToken: imaginaryAccessToken}
|
||||||
email, err := p.GetEmailAddress(session)
|
email, err := p.GetEmailAddress(session)
|
||||||
assert.NotEqual(t, nil, err)
|
assert.NotEqual(t, nil, err)
|
||||||
assert.Equal(t, "", email)
|
assert.Equal(t, "", email)
|
||||||
|
Loading…
Reference in New Issue
Block a user