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())
}