Skip to content
quarry Artifact [a8af3b6956]
Login

Artifact [a8af3b6956]

Artifact a8af3b6956de70e6396f6a9ca5d06235819586074412a666236533ce185591fc:


package xfer

import "testing"

// A read that is refused has to say which of the three things went
// wrong, because from outside they are one silent 404 and they want
// three different fixes.
func TestLoginStateSaysWhichCredentialFailed(t *testing.T) {
	cases := []struct {
		name string
		st   loginState
		want string
	}{
		{"nothing offered", loginState{}, "no credential offered"},
		{"basic only", loginState{basic: true}, "HTTP Basic offered, no login card"},
		{"card did not verify", loginState{offered: true}, "login card offered and did not verify"},
		{"no credential minted", loginState{offered: true, noSecret: true},
			"login card offered but this account has no push credential here"},
		{"verified", loginState{user: "jva", offered: true}, "login card verified as jva"},
	}
	for _, c := range cases {
		if got := c.st.why(); got != c.want {
			t.Errorf("FAIL %s: why() = %q, want %q", c.name, got, c.want)
			continue
		}
		t.Logf("ok %s: %s", c.name, c.st.why())
	}
}

// A verified account beats every other signal: whatever else the
// request carried, the account is what a reader of the journal needs.
func TestLoginStateVerifiedWinsOverBasic(t *testing.T) {
	st := loginState{user: "zeitgeist", offered: true, basic: true, noSecret: true}
	if got := st.why(); got != "login card verified as zeitgeist" {
		t.Fatalf("FAIL: why() = %q", got)
	}
	t.Logf("ok: %s", st.why())
}