forked from leaderboardsgg/leaderboard-backend-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_test.go
34 lines (26 loc) · 805 Bytes
/
auth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package middleware
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAuthMiddlewareInstalled(t *testing.T) {
authedHandler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
user := GetAuthedUser(r.Context())
assert.True(t, user.AuthRan)
assert.False(t, user.IsAuthed)
})
req, err := http.NewRequest("method", "url", nil)
assert.NoError(t, err)
AuthMiddleware(nil, req, authedHandler)
}
func TestAuthMiddlewareNotInstalled(t *testing.T) {
authedHandler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
user := GetAuthedUser(r.Context())
assert.False(t, user.AuthRan)
assert.False(t, user.IsAuthed)
})
req, err := http.NewRequest("method", "url", nil)
assert.NoError(t, err)
authedHandler.ServeHTTP(nil, req)
}