History

Convert to url auth to header auth in tests (#28484)

Related #28390

KN4CK3R committed 2 years ago

Commit 838db2f1 parent 04b235d102 files · +1714 −1522Browse files

Showing the changes to tests/integration/api_httpsig_test.go (1 of 102 files). Show all

Unified · Split

tests/integration/api_httpsig_test.go+7−7
@@ -5,7 +5,6 @@ package integration · 4 unmodified lines
55
66 import (
77 "encoding/base64"
8− "fmt"
98 "net/http"
109 "net/url"
1110 "testing"
@@ -57,14 +56,14 @@ func TestHTTPSigPubKey(t *testing.T) { · 45 unmodified lines
5756 defer test.MockVariableValue(&setting.SSH.MinimumKeySizeCheck, false)()
5857 session := loginUser(t, "user1")
5958 token := url.QueryEscape(getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser))
60− keysURL := fmt.Sprintf("/api/v1/user/keys?token=%s", token)
6159 keyType := "ssh-rsa"
6260 keyContent := "AAAAB3NzaC1yc2EAAAADAQABAAABAQCqOZB5vkRvXFXups1/0StDRdG8plbNSwsWEnNnP4Bvurxa0+z3W9B8GLKnDiLw5MbpbMNyBlpXw13GfuIeciy10DWTz0xUbiy3J3KabCaT36asIw2y7k6Z0jL0UBnrVENwq5/lUbZYqSZ4rRU744wkhh8TULpzM14npQCZwg6aEbG+MwjzddQ72fR+3BPBrKn5dTmmu8rH99O+U+Nuto81Tg7PA+NUupcHOmhdiEGq49plgVFXK98Vks5tiybL4GuzFyWgyX73Dg/QBMn2eMHt1EMv5Gs3i6GFhKKGo4rjDi9qI6PX5oDR4LTNe6cR8td8YhVD8WFZwLLl/vaYyIqd"
6361 rawKeyBody := api.CreateKeyOption{
6462 Title: "test-key",
6563 Key: keyType + " " + keyContent,
6664 }
67− req := NewRequestWithJSON(t, "POST", keysURL, rawKeyBody)
65+ req := NewRequestWithJSON(t, "POST", "/api/v1/user/keys", rawKeyBody).
66+ AddTokenAuth(token)
6867 MakeRequest(t, req, http.StatusCreated)
6968
7069 // parse our private key and create the httpsig request
@@ -73,7 +72,8 @@ func TestHTTPSigPubKey(t *testing.T) { · 2 unmodified lines
7372
7473 // create the request
7574 token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadAdmin)
76− req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/admin/users?token=%s", token))
75+ req = NewRequest(t, "GET", "/api/v1/admin/users").
76+ AddTokenAuth(token)
7777
7878 signer, _, err := httpsig.NewSSHSigner(sshSigner, httpsig.DigestSha512, []string{httpsig.RequestTarget, "(created)", "(expires)"}, httpsig.Signature, 10)
7979 if err != nil {
@@ -81,7 +81,7 @@ func TestHTTPSigPubKey(t *testing.T) { · 1 unmodified line
8181 }
8282
8383 // sign the request
84− err = signer.SignRequest(keyID, req, nil)
84+ err = signer.SignRequest(keyID, req.Request, nil)
8585 if err != nil {
8686 t.Fatal(err)
8787 }
@@ -124,7 +124,7 @@ func TestHTTPSigCert(t *testing.T) { · 36 unmodified lines
124124
125125 // add our cert to the request
126126 certString := base64.RawStdEncoding.EncodeToString(pkcert.(*ssh.Certificate).Marshal())
127− req.Header.Add("x-ssh-certificate", certString)
127+ req.SetHeader("x-ssh-certificate", certString)
128128
129129 signer, _, err := httpsig.NewSSHSigner(certSigner, httpsig.DigestSha512, []string{httpsig.RequestTarget, "(created)", "(expires)", "x-ssh-certificate"}, httpsig.Signature, 10)
130130 if err != nil {
@@ -132,7 +132,7 @@ func TestHTTPSigCert(t *testing.T) { · 1 unmodified line
132132 }
133133
134134 // sign the request
135− err = signer.SignRequest(keyID, req, nil)
135+ err = signer.SignRequest(keyID, req.Request, nil)
136136 if err != nil {
137137 t.Fatal(err)
138138 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t