@@ -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 ) {
@@ -75,3 +77,30 @@ func TestUsers(t *testing.T) {
75
77
require .Len (t , orgs , 1 )
76
78
})
77
79
}
80
+
81
+ func TestLogout (t * testing.T ) {
82
+ t .Parallel ()
83
+
84
+ t .Run ("LogoutShouldClearCookie" , func (t * testing.T ) {
85
+ t .Parallel ()
86
+
87
+ server := coderdtest .New (t )
88
+ fullURL , err := server .URL .Parse ("/api/v2/logout" )
89
+ require .NoError (t , err , "Server URL should parse successfully" )
90
+
91
+ req , err := http .NewRequestWithContext (context .Background (), http .MethodPost , fullURL .String (), nil )
92
+ require .NoError (t , err , "/logout request construction should succeed" )
93
+
94
+ httpClient := & http.Client {}
95
+
96
+ response , err := httpClient .Do (req )
97
+ require .NoError (t , err , "/logout request should succeed" )
98
+ response .Body .Close ()
99
+
100
+ cookies := response .Cookies ()
101
+ require .Len (t , cookies , 1 , "Exactly one cookie should be returned" )
102
+
103
+ require .Equal (t , cookies [0 ].Name , httpmw .AuthCookie , "Cookie should be the auth cookie" )
104
+ require .Equal (t , cookies [0 ].MaxAge , - 1 , "Cookie should be set to delete" )
105
+ })
106
+ }
0 commit comments