feat: enhance evobgp with new command-line tools for bundle management, including pull, verify, and apply functionalities. Update go.mod to include necessary dependencies and complete todos in architecture plan for improved observability and deployment practices.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package bundle
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildVerifyRoundtrip(t *testing.T) {
|
||||
_, priv, err := ed25519.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
frag := map[string]string{
|
||||
"bird.conf": "router id 192.0.2.1;\n\nprotocol device {\n}\n\nprotocol direct {\n ipv4;\n ipv6;\n}\n",
|
||||
}
|
||||
raw, err := BuildGzippedTar("rev-1", "sp-1", frag, priv)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pub := priv.Public().(ed25519.PublicKey)
|
||||
v, err := VerifyGzippedTar(raw, pub)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v.Manifest.RevisionID != "rev-1" {
|
||||
t.Fatalf("revision %q", v.Manifest.RevisionID)
|
||||
}
|
||||
if len(v.Files) != 1 {
|
||||
t.Fatalf("files %d", len(v.Files))
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyWrongKey(t *testing.T) {
|
||||
_, privA, err := ed25519.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, privB, err := ed25519.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, err := BuildGzippedTar("rev-x", "sp-x", map[string]string{"a.conf": "x"}, privA)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pubB := privB.Public().(ed25519.PublicKey)
|
||||
if _, err := VerifyGzippedTar(raw, pubB); err == nil {
|
||||
t.Fatal("expected signature error with wrong public key")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user