mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:17:33 +00:00
fix: improvements for login and oidc (#227)
* add csrf * caching * caching * caching * caching * security headers * csp and security headers * error handler csp * select user with display name * csp * user selection styling * username to loginname * regenerate grpc * regenerate * change to login name
This commit is contained in:
82
internal/api/http/middleware/cache_interceptor_test.go
Normal file
82
internal/api/http/middleware/cache_interceptor_test.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCache_serializeHeaders(t *testing.T) {
|
||||
type fields struct {
|
||||
Cacheability Cacheability
|
||||
NoCache bool
|
||||
NoStore bool
|
||||
MaxAge time.Duration
|
||||
SharedMaxAge time.Duration
|
||||
NoTransform bool
|
||||
Revalidation Revalidation
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
wantControl string
|
||||
wantExpires string
|
||||
wantPragma string
|
||||
}{
|
||||
{
|
||||
"no-store",
|
||||
fields{
|
||||
NoStore: true,
|
||||
},
|
||||
"no-store",
|
||||
time.Now().UTC().Add(-1 * time.Hour).Format(http.TimeFormat),
|
||||
"no-cache",
|
||||
},
|
||||
{
|
||||
"private and max-age",
|
||||
fields{
|
||||
Cacheability: CacheabilityPrivate,
|
||||
MaxAge: 1 * time.Hour,
|
||||
SharedMaxAge: 1 * time.Hour,
|
||||
},
|
||||
"private, max-age=3600",
|
||||
time.Now().UTC().Add(1 * time.Hour).Format(http.TimeFormat),
|
||||
"",
|
||||
},
|
||||
{
|
||||
"public, no-cache, proxy-revalidate",
|
||||
fields{
|
||||
Cacheability: CacheabilityPublic,
|
||||
NoCache: true,
|
||||
Revalidation: RevalidationProxy,
|
||||
},
|
||||
"public, max-age=0, no-cache, proxy-revalidate",
|
||||
time.Now().UTC().Add(-1 * time.Hour).Format(http.TimeFormat),
|
||||
"no-cache",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
c := &Cache{
|
||||
Cacheability: tt.fields.Cacheability,
|
||||
NoCache: tt.fields.NoCache,
|
||||
NoStore: tt.fields.NoStore,
|
||||
MaxAge: tt.fields.MaxAge,
|
||||
SharedMaxAge: tt.fields.SharedMaxAge,
|
||||
NoTransform: tt.fields.NoTransform,
|
||||
Revalidation: tt.fields.Revalidation,
|
||||
}
|
||||
c.serializeHeaders(recorder)
|
||||
cc := recorder.Result().Header.Get("cache-control")
|
||||
assert.Equal(t, tt.wantControl, cc)
|
||||
exp := recorder.Result().Header.Get("expires")
|
||||
assert.Equal(t, tt.wantExpires, exp)
|
||||
pragma := recorder.Result().Header.Get("pragma")
|
||||
assert.Equal(t, tt.wantPragma, pragma)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user