Related #28390
Showing the changes to tests/integration/api_httpsig_test.go (1 of 102 files). Show all
Unified · Split
| @@ -5,7 +5,6 @@ package integration · 4 unmodified lines | |||
| 5 | 5 | ||
| 6 | import ( | 6 | import ( |
| 7 | "encoding/base64" | 7 | "encoding/base64" |
| 8 | "fmt" | ||
| 9 | "net/http" | 8 | "net/http" |
| 10 | "net/url" | 9 | "net/url" |
| 11 | "testing" | 10 | "testing" |
| @@ -57,14 +56,14 @@ func TestHTTPSigPubKey(t *testing.T) { · 45 unmodified lines | |||
| 57 | defer test.MockVariableValue(&setting.SSH.MinimumKeySizeCheck, false)() | 56 | defer test.MockVariableValue(&setting.SSH.MinimumKeySizeCheck, false)() |
| 58 | session := loginUser(t, "user1") | 57 | session := loginUser(t, "user1") |
| 59 | token := url.QueryEscape(getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser)) | 58 | token := url.QueryEscape(getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser)) |
| 60 | keysURL := fmt.Sprintf("/api/v1/user/keys?token=%s", token) | ||
| 61 | keyType := "ssh-rsa" | 59 | keyType := "ssh-rsa" |
| 62 | keyContent := "AAAAB3NzaC1yc2EAAAADAQABAAABAQCqOZB5vkRvXFXups1/0StDRdG8plbNSwsWEnNnP4Bvurxa0+z3W9B8GLKnDiLw5MbpbMNyBlpXw13GfuIeciy10DWTz0xUbiy3J3KabCaT36asIw2y7k6Z0jL0UBnrVENwq5/lUbZYqSZ4rRU744wkhh8TULpzM14npQCZwg6aEbG+MwjzddQ72fR+3BPBrKn5dTmmu8rH99O+U+Nuto81Tg7PA+NUupcHOmhdiEGq49plgVFXK98Vks5tiybL4GuzFyWgyX73Dg/QBMn2eMHt1EMv5Gs3i6GFhKKGo4rjDi9qI6PX5oDR4LTNe6cR8td8YhVD8WFZwLLl/vaYyIqd" | 60 | keyContent := "AAAAB3NzaC1yc2EAAAADAQABAAABAQCqOZB5vkRvXFXups1/0StDRdG8plbNSwsWEnNnP4Bvurxa0+z3W9B8GLKnDiLw5MbpbMNyBlpXw13GfuIeciy10DWTz0xUbiy3J3KabCaT36asIw2y7k6Z0jL0UBnrVENwq5/lUbZYqSZ4rRU744wkhh8TULpzM14npQCZwg6aEbG+MwjzddQ72fR+3BPBrKn5dTmmu8rH99O+U+Nuto81Tg7PA+NUupcHOmhdiEGq49plgVFXK98Vks5tiybL4GuzFyWgyX73Dg/QBMn2eMHt1EMv5Gs3i6GFhKKGo4rjDi9qI6PX5oDR4LTNe6cR8td8YhVD8WFZwLLl/vaYyIqd" |
| 63 | rawKeyBody := api.CreateKeyOption{ | 61 | rawKeyBody := api.CreateKeyOption{ |
| 64 | Title: "test-key", | 62 | Title: "test-key", |
| 65 | Key: keyType + " " + keyContent, | 63 | Key: keyType + " " + keyContent, |
| 66 | } | 64 | } |
| 67 | req := NewRequestWithJSON(t, "POST", keysURL, rawKeyBody) | 65 | req := NewRequestWithJSON(t, "POST", "/api/v1/user/keys", rawKeyBody). |
| 66 | AddTokenAuth(token) | ||
| 68 | MakeRequest(t, req, http.StatusCreated) | 67 | MakeRequest(t, req, http.StatusCreated) |
| 69 | 68 | ||
| 70 | // parse our private key and create the httpsig request | 69 | // parse our private key and create the httpsig request |
| @@ -73,7 +72,8 @@ func TestHTTPSigPubKey(t *testing.T) { · 2 unmodified lines | |||
| 73 | 72 | ||
| 74 | // create the request | 73 | // create the request |
| 75 | token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadAdmin) | 74 | 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) | ||
| 77 | 77 | ||
| 78 | signer, _, err := httpsig.NewSSHSigner(sshSigner, httpsig.DigestSha512, []string{httpsig.RequestTarget, "(created)", "(expires)"}, httpsig.Signature, 10) | 78 | signer, _, err := httpsig.NewSSHSigner(sshSigner, httpsig.DigestSha512, []string{httpsig.RequestTarget, "(created)", "(expires)"}, httpsig.Signature, 10) |
| 79 | if err != nil { | 79 | if err != nil { |
| @@ -81,7 +81,7 @@ func TestHTTPSigPubKey(t *testing.T) { · 1 unmodified line | |||
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | // sign the request | 83 | // sign the request |
| 84 | err = signer.SignRequest(keyID, req, nil) | 84 | err = signer.SignRequest(keyID, req.Request, nil) |
| 85 | if err != nil { | 85 | if err != nil { |
| 86 | t.Fatal(err) | 86 | t.Fatal(err) |
| 87 | } | 87 | } |
| @@ -124,7 +124,7 @@ func TestHTTPSigCert(t *testing.T) { · 36 unmodified lines | |||
| 124 | 124 | ||
| 125 | // add our cert to the request | 125 | // add our cert to the request |
| 126 | certString := base64.RawStdEncoding.EncodeToString(pkcert.(*ssh.Certificate).Marshal()) | 126 | certString := base64.RawStdEncoding.EncodeToString(pkcert.(*ssh.Certificate).Marshal()) |
| 127 | req.Header.Add("x-ssh-certificate", certString) | 127 | req.SetHeader("x-ssh-certificate", certString) |
| 128 | 128 | ||
| 129 | signer, _, err := httpsig.NewSSHSigner(certSigner, httpsig.DigestSha512, []string{httpsig.RequestTarget, "(created)", "(expires)", "x-ssh-certificate"}, httpsig.Signature, 10) | 129 | signer, _, err := httpsig.NewSSHSigner(certSigner, httpsig.DigestSha512, []string{httpsig.RequestTarget, "(created)", "(expires)", "x-ssh-certificate"}, httpsig.Signature, 10) |
| 130 | if err != nil { | 130 | if err != nil { |
| @@ -132,7 +132,7 @@ func TestHTTPSigCert(t *testing.T) { · 1 unmodified line | |||
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | // sign the request | 134 | // sign the request |
| 135 | err = signer.SignRequest(keyID, req, nil) | 135 | err = signer.SignRequest(keyID, req.Request, nil) |
| 136 | if err != nil { | 136 | if err != nil { |
| 137 | t.Fatal(err) | 137 | t.Fatal(err) |
| 138 | } | 138 | } |