MCPcopy
hub / github.com/ory/hydra / TestValidateCsrfSession

Function TestValidateCsrfSession

consent/helper_test.go:67–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

65}
66
67func TestValidateCsrfSession(t *testing.T) {
68 const name = "oauth2_authentication_csrf"
69
70 type cookie struct {
71 name string
72 csrfValue string
73 sameSite http.SameSite
74 }
75 for k, tc := range []struct {
76 cookies []cookie
77 csrfValue string
78 sameSiteLegacyWorkaround bool
79 expectError bool
80 sameSite http.SameSite
81 }{
82 {
83 cookies: []cookie{},
84 csrfValue: "CSRF-VALUE",
85 sameSiteLegacyWorkaround: false,
86 expectError: true,
87 },
88 {
89 cookies: []cookie{},
90 csrfValue: "CSRF-VALUE",
91 sameSiteLegacyWorkaround: true,
92 expectError: true,
93 },
94 {
95 cookies: []cookie{
96 {
97 name: name,
98 csrfValue: "WRONG-CSRF-VALUE",
99 sameSite: http.SameSiteDefaultMode,
100 },
101 },
102 csrfValue: "CSRF-VALUE",
103 sameSiteLegacyWorkaround: false,
104 expectError: true,
105 },
106 {
107 cookies: []cookie{
108 {
109 name: name,
110 csrfValue: "WRONG-CSRF-VALUE",
111 sameSite: http.SameSiteDefaultMode,
112 },
113 },
114 csrfValue: "CSRF-VALUE",
115 sameSiteLegacyWorkaround: true,
116 expectError: true,
117 },
118 {
119 cookies: []cookie{
120 {
121 name: name,
122 csrfValue: "CSRF-VALUE",
123 sameSite: http.SameSiteDefaultMode,
124 },

Callers

nothing calls this directly

Calls 10

EXPECTMethod · 0.95
legacyCSRFCookieNameFunction · 0.85
validateCSRFCookieFunction · 0.85
IsDevelopmentModeMethod · 0.65
CookieSecureMethod · 0.65
CookieSameSiteModeMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected