-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgdrive_config_test.go
More file actions
59 lines (47 loc) · 1.62 KB
/
gdrive_config_test.go
File metadata and controls
59 lines (47 loc) · 1.62 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"encoding/base64"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHttpHandlerRoot(t *testing.T) {
h := newHttpHandler(context.Background(), func() {})
req := httptest.NewRequest("GET", "/", nil)
rw := httptest.NewRecorder()
h.ServeHTTP(rw, req)
assert.Equal(t, http.StatusOK, rw.Code)
}
func TestHttpHandlerLoginMissingFields(t *testing.T) {
h := newHttpHandler(context.Background(), func() {})
req := httptest.NewRequest("POST", "/login", strings.NewReader(""))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rw := httptest.NewRecorder()
h.ServeHTTP(rw, req)
assert.Equal(t, http.StatusBadRequest, rw.Code)
}
func TestHttpHandlerAuthInvalidState(t *testing.T) {
h := newHttpHandler(context.Background(), func() {})
req := httptest.NewRequest("GET", "/auth?state=invalid", nil)
rw := httptest.NewRecorder()
h.ServeHTTP(rw, req)
assert.Equal(t, http.StatusBadRequest, rw.Code)
}
func TestHttpHandlerGenerateMissingToken(t *testing.T) {
h := newHttpHandler(context.Background(), func() {})
req := httptest.NewRequest("POST", "/generate", nil)
rw := httptest.NewRecorder()
h.ServeHTTP(rw, req)
assert.Equal(t, http.StatusBadRequest, rw.Code)
}
func TestHttpHandlerGenerateMissingOidc(t *testing.T) {
h := newHttpHandler(context.Background(), func() {})
req := httptest.NewRequest("POST", "/generate", nil)
req.AddCookie(&http.Cookie{Name: "token", Value: base64.StdEncoding.EncodeToString([]byte("dummy"))})
rw := httptest.NewRecorder()
h.ServeHTTP(rw, req)
assert.Equal(t, http.StatusBadRequest, rw.Code)
}