Skip to content

Commit

Permalink
✅ Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
adyanth committed Mar 12, 2022
1 parent 35ededf commit 9931662
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions internal/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,71 @@ func TestRedirectUri(t *testing.T) {
assert.Equal("https", uri.Scheme)
assert.Equal("another.com", uri.Host)
assert.Equal("/_oauth", uri.Path)

//
// With correct Auth URL + cookie domain, multiple AuthHosts and cookie domains
// - will use matching authHost
//
config.AuthHosts = CommaSeparatedList{"auth.example.com", "auth.another.com"}
config.CookieDomains = []CookieDomain{*NewCookieDomain("example.com"), *NewCookieDomain("another.com")}

uri, err = url.Parse(redirectUri(r))
assert.Nil(err)
assert.Equal("https", uri.Scheme)
assert.Equal("auth.another.com", uri.Host)
assert.Equal("/_oauth", uri.Path)

//
// With correct Auth URL + no cookie domains
// - will not use authHost
//
config.AuthHosts = CommaSeparatedList{"auth.example.com", "auth.another.com"}
config.CookieDomains = []CookieDomain{}

uri, err = url.Parse(redirectUri(r))
assert.Nil(err)
assert.Equal("https", uri.Scheme)
assert.Equal("another.com", uri.Host)
assert.Equal("/_oauth", uri.Path)

//
// With correct Auth URL + no matching cookie domains
// - will not use authHost
//
config.AuthHosts = CommaSeparatedList{"auth.example.com", "auth.another.com"}
config.CookieDomains = []CookieDomain{*NewCookieDomain("example.com"), *NewCookieDomain("another.example")}

uri, err = url.Parse(redirectUri(r))
assert.Nil(err)
assert.Equal("https", uri.Scheme)
assert.Equal("another.com", uri.Host)
assert.Equal("/_oauth", uri.Path)

//
// With no matching Auth Host + matching cookie domains
// - will not use authHost
//
config.AuthHosts = CommaSeparatedList{"auth.example.com", "auth.another.example"}
config.CookieDomains = []CookieDomain{*NewCookieDomain("example.com"), *NewCookieDomain("another.com")}

uri, err = url.Parse(redirectUri(r))
assert.Nil(err)
assert.Equal("https", uri.Scheme)
assert.Equal("another.com", uri.Host)
assert.Equal("/_oauth", uri.Path)

//
// With no matching Auth Host + no matching cookie domains
// - will not use authHost
//
config.AuthHosts = CommaSeparatedList{"auth.example.com", "auth.another.example"}
config.CookieDomains = []CookieDomain{*NewCookieDomain("example.com"), *NewCookieDomain("another.example")}

uri, err = url.Parse(redirectUri(r))
assert.Nil(err)
assert.Equal("https", uri.Scheme)
assert.Equal("another.com", uri.Host)
assert.Equal("/_oauth", uri.Path)
}

func TestAuthMakeCookie(t *testing.T) {
Expand Down

0 comments on commit 9931662

Please sign in to comment.