forked from forgejo/forgejo
parent
04b235d094
commit
838db2f891
102 changed files with 1715 additions and 1523 deletions
|
@ -5,7 +5,6 @@ package integration
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
@ -57,14 +56,14 @@ func TestHTTPSigPubKey(t *testing.T) {
|
|||
defer test.MockVariableValue(&setting.SSH.MinimumKeySizeCheck, false)()
|
||||
session := loginUser(t, "user1")
|
||||
token := url.QueryEscape(getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser))
|
||||
keysURL := fmt.Sprintf("/api/v1/user/keys?token=%s", token)
|
||||
keyType := "ssh-rsa"
|
||||
keyContent := "AAAAB3NzaC1yc2EAAAADAQABAAABAQCqOZB5vkRvXFXups1/0StDRdG8plbNSwsWEnNnP4Bvurxa0+z3W9B8GLKnDiLw5MbpbMNyBlpXw13GfuIeciy10DWTz0xUbiy3J3KabCaT36asIw2y7k6Z0jL0UBnrVENwq5/lUbZYqSZ4rRU744wkhh8TULpzM14npQCZwg6aEbG+MwjzddQ72fR+3BPBrKn5dTmmu8rH99O+U+Nuto81Tg7PA+NUupcHOmhdiEGq49plgVFXK98Vks5tiybL4GuzFyWgyX73Dg/QBMn2eMHt1EMv5Gs3i6GFhKKGo4rjDi9qI6PX5oDR4LTNe6cR8td8YhVD8WFZwLLl/vaYyIqd"
|
||||
rawKeyBody := api.CreateKeyOption{
|
||||
Title: "test-key",
|
||||
Key: keyType + " " + keyContent,
|
||||
}
|
||||
req := NewRequestWithJSON(t, "POST", keysURL, rawKeyBody)
|
||||
req := NewRequestWithJSON(t, "POST", "/api/v1/user/keys", rawKeyBody).
|
||||
AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
// parse our private key and create the httpsig request
|
||||
|
@ -73,7 +72,8 @@ func TestHTTPSigPubKey(t *testing.T) {
|
|||
|
||||
// create the request
|
||||
token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadAdmin)
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/admin/users?token=%s", token))
|
||||
req = NewRequest(t, "GET", "/api/v1/admin/users").
|
||||
AddTokenAuth(token)
|
||||
|
||||
signer, _, err := httpsig.NewSSHSigner(sshSigner, httpsig.DigestSha512, []string{httpsig.RequestTarget, "(created)", "(expires)"}, httpsig.Signature, 10)
|
||||
if err != nil {
|
||||
|
@ -81,7 +81,7 @@ func TestHTTPSigPubKey(t *testing.T) {
|
|||
}
|
||||
|
||||
// sign the request
|
||||
err = signer.SignRequest(keyID, req, nil)
|
||||
err = signer.SignRequest(keyID, req.Request, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ func TestHTTPSigCert(t *testing.T) {
|
|||
|
||||
// add our cert to the request
|
||||
certString := base64.RawStdEncoding.EncodeToString(pkcert.(*ssh.Certificate).Marshal())
|
||||
req.Header.Add("x-ssh-certificate", certString)
|
||||
req.SetHeader("x-ssh-certificate", certString)
|
||||
|
||||
signer, _, err := httpsig.NewSSHSigner(certSigner, httpsig.DigestSha512, []string{httpsig.RequestTarget, "(created)", "(expires)", "x-ssh-certificate"}, httpsig.Signature, 10)
|
||||
if err != nil {
|
||||
|
@ -132,7 +132,7 @@ func TestHTTPSigCert(t *testing.T) {
|
|||
}
|
||||
|
||||
// sign the request
|
||||
err = signer.SignRequest(keyID, req, nil)
|
||||
err = signer.SignRequest(keyID, req.Request, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue