MCPcopy Create free account
hub / github.com/crewjam/saml / TestCreateLinkRejectsBadRequests

Function TestCreateLinkRejectsBadRequests

example/service_test.go:85–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func TestCreateLinkRejectsBadRequests(t *testing.T) {
86 resetLinks(t)
87 for _, tc := range []struct {
88 name, target, account string
89 want int
90 }{
91 {"no session", "https://example.com/", "", http.StatusForbidden},
92 {"empty target", "", "alice", http.StatusBadRequest},
93 {"relative target", "/foo", "alice", http.StatusBadRequest},
94 {"javascript target", "javascript:alert(1)", "alice", http.StatusBadRequest},
95 } {
96 t.Run(tc.name, func(t *testing.T) {
97 w := httptest.NewRecorder()
98 CreateLink(w, requestAs(http.MethodPost, url.Values{"t": {tc.target}}.Encode(), tc.account))
99 if w.Code != tc.want {
100 t.Errorf("got %d, want %d", w.Code, tc.want)
101 }
102 })
103 }
104}
105
106func TestLinksConcurrentAccess(t *testing.T) {
107 resetLinks(t)

Callers

nothing calls this directly

Calls 4

resetLinksFunction · 0.85
CreateLinkFunction · 0.85
requestAsFunction · 0.85
EncodeMethod · 0.65

Tested by

no test coverage detected