Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package store
|
|
|
|
import (
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"crypto/sha256"
|
|
"encoding/base64"
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
func TestFederationCapabilityProof(t *testing.T) {
|
|
st := manifestIntegrityStore(t)
|
|
if err := st.CreateCampus("caps", "Caps", "en", "controller", "caps.example.test", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var campus string
|
|
if err := st.DB.QueryRow(`SELECT uuid FROM campuses WHERE name='caps'`).Scan(&campus); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
token, err := st.IssueCampusToken(campus, "fixture")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pub, priv, err := ed25519.GenerateKey(rand.Reader)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sum := sha256.Sum256(pub)
|
|
fp := "sha256:" + hex.EncodeToString(sum[:])
|
|
fqdn := "node.example.test"
|
|
enc := base64.RawStdEncoding.EncodeToString
|
|
proof := enc(ed25519.Sign(priv, []byte(fqdn+"\n"+token)))
|
|
cap := FederationCapabilities{ManifestVersion: 2, Signature: enc(ed25519.Sign(priv, []byte(FederationCapabilityMessage(fqdn, token))))}
|
|
_, node, err := st.RegisterFederationInstance(token, fqdn, fp, enc(pub), proof, cap)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var version int
|
|
if err = st.DB.QueryRow(`SELECT manifest_version FROM federation_instance_capabilities WHERE instance_uuid=?`, node.UUID).Scan(&version); err != nil || version != 2 {
|
|
t.Fatal(version, err)
|
|
}
|
|
cap.Signature = proof
|
|
if _, _, err = st.RegisterFederationInstance(token, fqdn, fp, enc(pub), proof, cap); err == nil {
|
|
t.Fatal("legacy proof accepted as capability proof")
|
|
}
|
|
if _, _, err = st.RegisterFederationInstance(token, fqdn, fp, enc(pub), proof); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = st.DB.QueryRow(`SELECT manifest_version FROM federation_instance_capabilities WHERE instance_uuid=?`, node.UUID).Scan(&version); err != nil || version != 1 {
|
|
t.Fatal("downgrade not recorded", version, err)
|
|
}
|
|
}
|