(t *testing.T)
| 27 | ) |
| 28 | |
| 29 | func TestGuestOnly(t *testing.T) { |
| 30 | db := testutils.InitMemoryDB(t) |
| 31 | |
| 32 | handler := func(w http.ResponseWriter, r *http.Request) { |
| 33 | w.WriteHeader(http.StatusOK) |
| 34 | } |
| 35 | |
| 36 | server := httptest.NewServer(GuestOnly(db, handler)) |
| 37 | defer server.Close() |
| 38 | |
| 39 | t.Run("guest", func(t *testing.T) { |
| 40 | req := testutils.MakeReq(server.URL, "GET", "/", "") |
| 41 | res := testutils.HTTPDo(t, req) |
| 42 | |
| 43 | assert.Equal(t, res.StatusCode, http.StatusOK, "status code mismatch") |
| 44 | }) |
| 45 | |
| 46 | t.Run("logged in", func(t *testing.T) { |
| 47 | user := testutils.SetupUserData(db, "user@test.com", "password123") |
| 48 | req := testutils.MakeReq(server.URL, "GET", "/", "") |
| 49 | res := testutils.HTTPAuthDo(t, db, req, user) |
| 50 | |
| 51 | assert.Equal(t, res.StatusCode, http.StatusFound, "status code mismatch") |
| 52 | assert.Equal(t, res.Header.Get("Location"), "/", "location mismatch") |
| 53 | }) |
| 54 | |
| 55 | t.Run("error getting credential", func(t *testing.T) { |
| 56 | req := testutils.MakeReq(server.URL, "GET", "/", "") |
| 57 | req.Header.Set("Authorization", "InvalidFormat") |
| 58 | res := testutils.HTTPDo(t, req) |
| 59 | |
| 60 | assert.Equal(t, res.StatusCode, http.StatusOK, "status code mismatch") |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | func TestAuth(t *testing.T) { |
| 65 | db := testutils.InitMemoryDB(t) |
nothing calls this directly
no test coverage detected