@@ -1526,54 +1526,66 @@ func TestCookies(t *testing.T) {
15261526
15271527func TestBasicAuth (t * testing.T ) {
15281528 t .Run ("ok" , func (t * testing.T ) {
1529- t .Parallel ()
1530-
1531- req := newTestRequest (t , "GET" , "/basic-auth/user/pass" )
1532- req .SetBasicAuth ("user" , "pass" )
1533-
1534- resp := must .DoReq (t , client , req )
1535- result := mustParseResponse [authResponse ](t , resp )
1536- expectedResult := authResponse {
1537- Authorized : true ,
1538- User : "user" ,
1529+ for _ , method := range []string {"GET" , "POST" , "PUT" , "DELETE" , "PATCH" } {
1530+ method := method
1531+ t .Run (method , func (t * testing.T ) {
1532+ t .Parallel ()
1533+ req := newTestRequest (t , method , "/basic-auth/user/pass" )
1534+ req .SetBasicAuth ("user" , "pass" )
1535+
1536+ resp := must .DoReq (t , client , req )
1537+ result := mustParseResponse [authResponse ](t , resp )
1538+ expectedResult := authResponse {
1539+ Authorized : true ,
1540+ User : "user" ,
1541+ }
1542+ assert .DeepEqual (t , result , expectedResult , "expected authorized user" )
1543+ })
15391544 }
1540- assert .DeepEqual (t , result , expectedResult , "expected authorized user" )
15411545 })
15421546
15431547 t .Run ("error/no auth" , func (t * testing.T ) {
1544- t .Parallel ()
1545-
1546- req := newTestRequest (t , "GET" , "/basic-auth/user/pass" )
1547- resp := must .DoReq (t , client , req )
1548- assert .StatusCode (t , resp , http .StatusUnauthorized )
1549- assert .ContentType (t , resp , jsonContentType )
1550- assert .Header (t , resp , "WWW-Authenticate" , `Basic realm="Fake Realm"` )
1551-
1552- result := must .Unmarshal [authResponse ](t , resp .Body )
1553- expectedResult := authResponse {
1554- Authorized : false ,
1555- User : "" ,
1548+ for _ , method := range []string {"GET" , "POST" , "PUT" , "DELETE" , "PATCH" } {
1549+ method := method
1550+ t .Run (method , func (t * testing.T ) {
1551+ t .Parallel ()
1552+ req := newTestRequest (t , method , "/basic-auth/user/pass" )
1553+ resp := must .DoReq (t , client , req )
1554+ assert .StatusCode (t , resp , http .StatusUnauthorized )
1555+ assert .ContentType (t , resp , jsonContentType )
1556+ assert .Header (t , resp , "WWW-Authenticate" , `Basic realm="Fake Realm"` )
1557+
1558+ result := must .Unmarshal [authResponse ](t , resp .Body )
1559+ expectedResult := authResponse {
1560+ Authorized : false ,
1561+ User : "" ,
1562+ }
1563+ assert .DeepEqual (t , result , expectedResult , "expected unauthorized user" )
1564+ })
15561565 }
1557- assert .DeepEqual (t , result , expectedResult , "expected unauthorized user" )
15581566 })
15591567
15601568 t .Run ("error/bad auth" , func (t * testing.T ) {
1561- t .Parallel ()
1562-
1563- req := newTestRequest (t , "GET" , "/basic-auth/user/pass" )
1564- req .SetBasicAuth ("bad" , "auth" )
1565-
1566- resp := must .DoReq (t , client , req )
1567- assert .StatusCode (t , resp , http .StatusUnauthorized )
1568- assert .ContentType (t , resp , jsonContentType )
1569- assert .Header (t , resp , "WWW-Authenticate" , `Basic realm="Fake Realm"` )
1570-
1571- result := must .Unmarshal [authResponse ](t , resp .Body )
1572- expectedResult := authResponse {
1573- Authorized : false ,
1574- User : "bad" ,
1569+ for _ , method := range []string {"GET" , "POST" , "PUT" , "DELETE" , "PATCH" } {
1570+ method := method
1571+ t .Run (method , func (t * testing.T ) {
1572+ t .Parallel ()
1573+ req := newTestRequest (t , method , "/basic-auth/user/pass" )
1574+ req .SetBasicAuth ("bad" , "auth" )
1575+
1576+ resp := must .DoReq (t , client , req )
1577+ assert .StatusCode (t , resp , http .StatusUnauthorized )
1578+ assert .ContentType (t , resp , jsonContentType )
1579+ assert .Header (t , resp , "WWW-Authenticate" , `Basic realm="Fake Realm"` )
1580+
1581+ result := must .Unmarshal [authResponse ](t , resp .Body )
1582+ expectedResult := authResponse {
1583+ Authorized : false ,
1584+ User : "bad" ,
1585+ }
1586+ assert .DeepEqual (t , result , expectedResult , "expected unauthorized user" )
1587+ })
15751588 }
1576- assert .DeepEqual (t , result , expectedResult , "expected unauthorized user" )
15771589 })
15781590
15791591 errorTests := []struct {
0 commit comments