50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package main
|
|
|
|
// [D.5] connector init scaffolds a manifest whose ONLY validation finding is
|
|
// the pending canary, and the generated webhook starter calls the real P1.4
|
|
// helper with its actual signature.
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"go.attesto.eu/sdk/connectorkit"
|
|
)
|
|
|
|
func TestConnectorInitScaffoldsValidManifest(t *testing.T) {
|
|
dir := filepath.Join(t.TempDir(), "my-crm")
|
|
a := &app{out: &bytes.Buffer{}, err: &bytes.Buffer{}}
|
|
if err := a.connectorInit([]string{"my-crm-evidence", "--category", "crm", "--dir", dir}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
raw, err := os.ReadFile(filepath.Join(dir, "attesto.connector.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var manifest connectorkit.Manifest
|
|
if err := json.Unmarshal(raw, &manifest); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
result := connectorkit.ValidateManifest(manifest)
|
|
for _, finding := range result.Findings {
|
|
if finding.Code != "runtime.canary" {
|
|
t.Fatalf("unexpected finding: %+v", finding)
|
|
}
|
|
}
|
|
handler, err := os.ReadFile(filepath.Join(dir, "webhook_handler.py"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(handler), "from attesto.webhooks import verify_webhook") {
|
|
t.Fatal("generated handler does not use the P1.4 helper")
|
|
}
|
|
// re-running must refuse to overwrite
|
|
if err := a.connectorInit([]string{"my-crm-evidence", "--dir", dir}); err == nil {
|
|
t.Fatal("expected overwrite refusal")
|
|
}
|
|
}
|