feat: deliver deployment verification keys and instance trust config
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
39
backend/internal/httpapi/integration_trust_test.go
Normal file
39
backend/internal/httpapi/integration_trust_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIntegrationTrust(t *testing.T) {
|
||||
const public = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAESr8/VFFwt70o7fwa8HiRNyxWtZEu\nUqzCBfYRG72DazEgeOaSVAdlTv49OujtggXSJzFLOluMENJzaRmp9+iJ0Q==\n-----END PUBLIC KEY-----\n"
|
||||
for _, configured := range []bool{false, true} {
|
||||
a := &BusinessAPI{}
|
||||
if configured {
|
||||
a.keyring = &Keyring{Current: "prod-test", Keys: []VerificationKey{{KeyID: "prod-test", PublicKeyPEM: public}, {KeyID: "old", PublicKeyPEM: public, Revoked: true}}}
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := gin.CreateTestContext(w)
|
||||
a.integrationTrust(c)
|
||||
if !configured {
|
||||
if w.Code != 503 {
|
||||
t.Fatal(w.Code)
|
||||
}
|
||||
continue
|
||||
}
|
||||
body := w.Body.String()
|
||||
if w.Code != 200 || !strings.Contains(body, "22056bfacc8fe8a240dd2125b629e60ba9f4a5ea0041a1efe034f376a258d562") || !strings.Contains(body, `"revoked":true`) || strings.Contains(body, "PRIVATE KEY") || w.Header().Get("Cache-Control") != "no-store" {
|
||||
t.Fatal("invalid trust response")
|
||||
}
|
||||
}
|
||||
r := gin.New()
|
||||
RegisterBusiness(r, &sql.DB{})
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, httptest.NewRequest("GET", "/api/v1/integration-trust", nil))
|
||||
if w.Code != 401 {
|
||||
t.Fatal("unauthenticated trust access")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user