Skip to content
quarry Artifact [bf87dadbdb]
Login

Artifact [bf87dadbdb]

Artifact bf87dadbdb9e0baa8e75115c5bd367e18e2ca1b820c10a5dd9bf88b44e8ba4fb:


package main

import (
	"errors"
	"path/filepath"
	"testing"

	"craftdesign.group/quarry/internal/oltp"
	"craftdesign.group/quarry/internal/ops"
)

// Rotate-secret and ping name the repository too: an admin of one
// repository holding another's endpoint id gets not found, and the
// secret is untouched.
func TestRotateAndPingRefuseAForeignEndpoint(t *testing.T) {
	db, err := oltp.Open(filepath.Join(t.TempDir(), "o.db"))
	if err != nil {
		t.Fatal(err)
	}
	t.Cleanup(func() { db.Close() })
	w, err := db.AddWebhook("alpha", "https://example.test/h", "*")
	if err != nil {
		t.Fatal(err)
	}
	if _, err := (hookStore{db: db}).RotateWebhookSecret("beta", w.ID); !errors.Is(err, ops.ErrNotFound) {
		t.Errorf("FAIL: rotate with a foreign repository: %v", err)
	}
	if _, err := (hookSender{db: db}).Ping("beta", w.ID); !errors.Is(err, ops.ErrNotFound) {
		t.Errorf("FAIL: ping with a foreign repository: %v", err)
	}
	if got, _ := db.WebhookByID(w.ID); got.Secret != w.Secret || got.OldSecret != "" {
		t.Errorf("FAIL: a foreign rotate changed the secret")
	}
	if !t.Failed() {
		t.Log("ok")
	}
}