Skip to content
quarry Artifact [2bd4c496bb]
Login

Artifact [2bd4c496bb]

Artifact 2bd4c496bbd5bb4c3a88ecbf691a59ed6db760f6aa0d274da0917fe9a151a890:


package oltp

import "testing"

// A token that has reported and one that never has must be tellable
// apart, or "which of these can I revoke?" has no answer. The stamp is
// written by the check that admits a report, and only by a token that
// was actually accepted.
func TestReporterTokenRecordsItsLastUse(t *testing.T) {
	d := testDB(t)
	tok, err := d.MintReporterToken("alpha", "runner")
	if err != nil {
		t.Fatal(err)
	}
	ts, err := d.ReporterTokens("alpha")
	if err != nil || len(ts) != 1 {
		t.Fatalf("tokens %v err %v", ts, err)
	}
	if ts[0].Used != "" {
		t.Errorf("a freshly minted token claims a use: %q", ts[0].Used)
	}
	if !d.CheckReporterToken("alpha", tok) {
		t.Fatal("the minted token was refused")
	}
	ts, _ = d.ReporterTokens("alpha")
	if ts[0].Used == "" {
		t.Error("an accepted report left no last-used stamp")
	}
	// A wrong token is not this token being used.
	before := ts[0].Used
	if d.CheckReporterToken("alpha", "qcr_nonsense") {
		t.Fatal("a token nobody minted was accepted")
	}
	ts, _ = d.ReporterTokens("alpha")
	if ts[0].Used != before {
		t.Error("a refused token moved another token's last-used")
	}
}