feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"sea-vhost/internal/dnsprovider"
|
||||
"sea-vhost/internal/secrets"
|
||||
"sea-vhost/internal/store"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDNSZoneChoiceBindsOwnerCredentialAndZone(t *testing.T) {
|
||||
s := &Projects{credentials: secrets.New("dns-proof-test-secret-at-least-thirty-two-bytes")}
|
||||
owner := uint64(12)
|
||||
u := store.User{Role: "tenant", TenantID: &owner}
|
||||
c := dnsprovider.Credential{APIToken: "fixture-api-token-with-sufficient-length", ZoneID: "zone12345678"}
|
||||
proof := dnsZoneProof{Owner: "tenant:12", Provider: "cloudflare", Hash: credentialHash(c), ID: c.ZoneID, Zone: "example.com", Expires: time.Now().Add(time.Minute).Unix()}
|
||||
raw, _ := json.Marshal(proof)
|
||||
sealed, e := s.credentials.Seal("dns-zone-choice", string(raw))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
input := DNSCredentialInput{Provider: "cloudflare", ZoneName: "example.com", Credential: c, VerificationToken: hex.EncodeToString(sealed)}
|
||||
if e = s.verifyDNSZoneChoice(u, false, input); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
other := input
|
||||
other.ZoneName = "victim.example"
|
||||
if s.verifyDNSZoneChoice(u, false, other) == nil {
|
||||
t.Fatal("zone substitution accepted")
|
||||
}
|
||||
other = input
|
||||
other.Credential.ZoneID = "another-zone"
|
||||
if s.verifyDNSZoneChoice(u, false, other) == nil {
|
||||
t.Fatal("zone ID substitution accepted")
|
||||
}
|
||||
other = input
|
||||
other.Credential.APIToken = "different-api-token"
|
||||
if s.verifyDNSZoneChoice(u, false, other) == nil {
|
||||
t.Fatal("credential substitution accepted")
|
||||
}
|
||||
second := uint64(13)
|
||||
if s.verifyDNSZoneChoice(store.User{Role: "tenant", TenantID: &second}, false, input) == nil {
|
||||
t.Fatal("cross-account proof accepted")
|
||||
}
|
||||
if s.verifyDNSZoneChoice(store.User{Role: "admin"}, true, input) == nil {
|
||||
t.Fatal("tenant proof accepted as platform credentials")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user