(t *testing.T)
| 83 | } |
| 84 | |
| 85 | func 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 | |
| 106 | func TestLinksConcurrentAccess(t *testing.T) { |
| 107 | resetLinks(t) |
nothing calls this directly
no test coverage detected