@@ -2,12 +2,14 @@ package coderd_test
2
2
3
3
import (
4
4
"context"
5
+ "net/http"
5
6
"testing"
6
7
7
8
"github.com/stretchr/testify/require"
8
9
9
10
"github.com/coder/coder/coderd"
10
11
"github.com/coder/coder/coderd/coderdtest"
12
+ "github.com/coder/coder/httpmw"
11
13
)
12
14
13
15
func TestUsers (t * testing.T ) {
@@ -74,3 +76,30 @@ func TestUsers(t *testing.T) {
74
76
require .Len (t , orgs , 1 )
75
77
})
76
78
}
79
+
80
+ func TestLogout (t * testing.T ) {
81
+ t .Parallel ()
82
+
83
+ t .Run ("LogoutShouldClearCookie" , func (t * testing.T ) {
84
+ t .Parallel ()
85
+
86
+ server := coderdtest .New (t )
87
+ fullURL , err := server .URL .Parse ("/api/v2/logout" )
88
+ require .NoError (t , err , "Server URL should parse successfully" )
89
+
90
+ req , err := http .NewRequestWithContext (context .Background (), http .MethodPost , fullURL .String (), nil )
91
+ require .NoError (t , err , "/logout request construction should succeed" )
92
+
93
+ httpClient := & http.Client {}
94
+
95
+ response , err := httpClient .Do (req )
96
+ require .NoError (t , err , "/logout request should succeed" )
97
+ response .Body .Close ()
98
+
99
+ cookies := response .Cookies ()
100
+ require .Len (t , cookies , 1 , "Exactly one cookie should be returned" )
101
+
102
+ require .Equal (t , cookies [0 ].Name , httpmw .AuthCookie , "Cookie should be the auth cookie" )
103
+ require .Equal (t , cookies [0 ].MaxAge , - 1 , "Cookie should be set to delete" )
104
+ })
105
+ }
0 commit comments