Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Added more coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Prafulla Mahindrakar <[email protected]>
  • Loading branch information
pmahindrakar-oss committed Jun 7, 2022
1 parent 7021d78 commit bd08dcd
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions auth/cookie_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,50 @@ func TestCookieManager_DeleteCookies(t *testing.T) {
assert.True(t, time.Now().After(cookies[0].Expires))
assert.True(t, time.Now().After(cookies[1].Expires))
}

func TestGetHTTPSameSitePolicy(t *testing.T) {
ctx := context.Background()

// These were generated for unit testing only.
hashKeyEncoded := "wG4pE1ccdw/pHZ2ml8wrD5VJkOtLPmBpWbKHmezWXktGaFbRoAhXidWs8OpbA3y7N8vyZhz1B1E37+tShWC7gA" //nolint:goconst
blockKeyEncoded := "afyABVgGOvWJFxVyOvCWCupoTn6BkNl4SOHmahho16Q" //nolint:goconst
cookieSetting := config.CookieSettings{
SameSitePolicy: config.SameSiteDefaultMode,
DomainMatchPolicy: config.DomainMatchSubdomains,
}

manager, err := NewCookieManager(ctx, hashKeyEncoded, blockKeyEncoded, cookieSetting)
assert.NoError(t, err)
assert.Equal(t, http.SameSiteDefaultMode, manager.getHTTPSameSitePolicy())

manager.sameSitePolicy = config.SameSiteLaxMode
assert.Equal(t, http.SameSiteLaxMode, manager.getHTTPSameSitePolicy())

manager.sameSitePolicy = config.SameSiteStrictMode
assert.Equal(t, http.SameSiteStrictMode, manager.getHTTPSameSitePolicy())

manager.sameSitePolicy = config.SameSiteNoneMode
assert.Equal(t, http.SameSiteNoneMode, manager.getHTTPSameSitePolicy())
}

func TestGetCookieDomain(t *testing.T) {
ctx := context.Background()

// These were generated for unit testing only.
hashKeyEncoded := "wG4pE1ccdw/pHZ2ml8wrD5VJkOtLPmBpWbKHmezWXktGaFbRoAhXidWs8OpbA3y7N8vyZhz1B1E37+tShWC7gA" //nolint:goconst
blockKeyEncoded := "afyABVgGOvWJFxVyOvCWCupoTn6BkNl4SOHmahho16Q" //nolint:goconst
cookieSetting := config.CookieSettings{
SameSitePolicy: config.SameSiteDefaultMode,
DomainMatchPolicy: config.DomainMatchSubdomains,
}

req, err := http.NewRequest("GET", "http://localhost/api/v1/projects", nil)
assert.NoError(t, err)

manager, err := NewCookieManager(ctx, hashKeyEncoded, blockKeyEncoded, cookieSetting)
assert.NoError(t, err)
assert.Equal(t, ".localhost", manager.getCookieDomain(req))

manager.domainMatchPolicy = config.DomainMatchExact
assert.Equal(t, "", manager.getCookieDomain(req))
}

0 comments on commit bd08dcd

Please sign in to comment.