Skip to content
quarry Artifact [f48464a3d8]
Login

Artifact [f48464a3d8]

Artifact f48464a3d8a2a9eed5c67dcd2e88f1085debbd490ff106af278b057e39046808:


package api

import (
	"context"
	"testing"

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

// An op that asks for the caller's letters itself, past the router's
// check, gets the token's letters when the request came in on a token
// (RFC 0021). landing.accept's gate for a repository other than the one
// the request named is the representative: the router only resolved the
// named repository, so this check is the whole of the gate there.
func TestAnOpsOwnLetterCheckHonoursTheTokensCeiling(t *testing.T) {
	d := Deps{CapsFor: func(string, string) CapSet { return oltp.CapSet("oi") },
		TrustedAuthor: func(string, string) bool { return true }}
	jan := ops.WithUser(context.Background(), "jan")
	if !d.mayAcceptIn(jan, "jan", "elsewhere") {
		t.Fatalf("FAIL: the account's own i does not accept")
	}
	readOnly := ops.WithToken(jan, ops.TokenAuth{ID: "T1", Caps: func(string) ops.Caps { return oltp.CapSet("o") }})
	if d.mayAcceptIn(readOnly, "jan", "elsewhere") {
		t.Errorf("FAIL: a token ceilinged to o accepted a landing")
	} else {
		t.Log("ok: the token's ceiling binds the op's own check")
	}
	// Another account's letters are still that account's.
	if !d.mayAcceptIn(readOnly, "kim", "elsewhere") {
		t.Errorf("FAIL: the caller's token narrowed somebody else's letters")
	}
	if d.trustedAuthor(readOnly, "jan", "elsewhere") {
		t.Errorf("FAIL: a token without 4 or 5 is a trusted forum author")
	}
}