66 "strings"
77 "testing"
88
9- "github.com/go-resty/resty/v2"
109 "github.com/stretchr/testify/assert"
1110 "github.com/stretchr/testify/require"
11+ "resty.dev/v3"
1212)
1313
1414const (
@@ -331,25 +331,37 @@ func TestNokiaGateway_NotImplemented(t *testing.T) {
331331 })
332332}
333333
334- func TestNokiaGateway_logout_ClearsCookie (t * testing.T ) {
335- ts := newTestServer (t , func (w http.ResponseWriter , _ * http.Request ) {
334+ func TestNokiaGateway_logout_ClearsCredentials (t * testing.T ) {
335+ gw := newNokia (& GatewayCommon {config : & GatewayConfig {}}, testValidSID , testValidToken )
336+
337+ gw .logout ()
338+
339+ assert .False (t , gw .isLoggedIn (), "logout should clear credentials" )
340+ }
341+
342+ func TestNokiaGateway_Reboot_SendsSIDCookie (t * testing.T ) {
343+ // Reboot must include the current session SID in the request cookie.
344+ var gotCookie string
345+
346+ ts := newTestServer (t , func (w http.ResponseWriter , r * http.Request ) {
336347 w .WriteHeader (http .StatusOK )
348+
349+ if r .Method == http .MethodPost && r .URL .Path == "/reboot_web_app.cgi" {
350+ if c , err := r .Cookie (sidCookieName ); err == nil {
351+ gotCookie = c .Value
352+ }
353+ }
337354 })
338355
339356 gw := nokiaTestGw (ts , nokiaConfig (ts ), testValidSID , testValidToken )
340- //nolint:gosec // Secure/HttpOnly/SameSite only apply to response cookies, not outgoing requests.
341- gw .client .SetCookie (& http.Cookie {Name : sidCookieName , Value : testValidSID })
342-
343- gw .logout ()
344357
345- assert . False (t , gw .isLoggedIn (), "logout should clear credentials" )
346- assert .Empty (t , gw . client . Cookies , "logout should clear all resty cookies " )
358+ require . NoError (t , gw .Reboot ( t . Context ()) )
359+ assert .Equal (t , testValidSID , gotCookie , "reboot request must carry the session SID cookie " )
347360}
348361
349- func TestNokiaGateway_Reboot_ReloginNoDuplicateCookie (t * testing.T ) {
350- // After reboot (which calls logout), a subsequent Login should not
351- // accumulate a second sid cookie from the previous session.
352- callCount := 0
362+ func TestNokiaGateway_Reboot_ReloginHasFreshSID (t * testing.T ) {
363+ // After reboot (which calls logout), a subsequent Login must use fresh credentials,
364+ // not carry over the old SID.
353365 ts := newTestServer (t , func (w http.ResponseWriter , r * http.Request ) {
354366 w .Header ().Set ("Content-Type" , "application/json" )
355367 w .WriteHeader (http .StatusOK )
@@ -358,34 +370,22 @@ func TestNokiaGateway_Reboot_ReloginNoDuplicateCookie(t *testing.T) {
358370 case r .Method == http .MethodGet :
359371 _ , _ = w .Write ([]byte (testNonceBody ))
360372 case r .Method == http .MethodPost && r .URL .Path == loginWebAppCGI :
361- callCount ++
362373 _ , _ = w .Write ([]byte (testLoginRespBody ))
363- case r .Method == http .MethodPost && r .URL .Path == "/reboot_web_app.cgi" :
364- // pass
365374 }
366375 })
367376
368377 gw := nokiaTestGw (ts , nokiaConfig (ts ), testValidSID , testValidToken )
369- //nolint:gosec // Secure/HttpOnly/SameSite only apply to response cookies, not outgoing requests.
370- gw .client .SetCookie (& http.Cookie {Name : sidCookieName , Value : testValidSID })
371378
372379 require .NoError (t , gw .Reboot (t .Context ()))
373380 require .NoError (t , gw .Login (t .Context ()))
374381
375- sidCookies := 0
376-
377- for _ , c := range gw .client .Cookies {
378- if c .Name == sidCookieName {
379- sidCookies ++
380- }
381- }
382-
383382 assert .Equal (
384383 t ,
385- 1 ,
386- sidCookies ,
387- "re-login after reboot must not accumulate duplicate sid cookies " ,
384+ "testSid" ,
385+ gw . credentials . SID ,
386+ "re-login after reboot must have fresh SID, not the old one " ,
388387 )
388+ assert .NotEqual (t , testValidSID , gw .credentials .SID )
389389}
390390
391391func TestNewNokiaGateway (t * testing.T ) {
0 commit comments