|
|
|
@@ -371,28 +371,38 @@ func TestALoginNotHandedIsNeverWrittenOverAndItsSuccessorReplacesIt(t *testing.T
|
|
|
|
|
name, file string
|
|
|
|
|
handed bool
|
|
|
|
|
offeredRTE int64 // the refresh token expiry the grant offered carries, 0 for none
|
|
|
|
|
offeredExp int64 // its access expiry, 0 for an hour from now
|
|
|
|
|
heard func(p Paths, ask Ask, w WriteManaged) (string, error)
|
|
|
|
|
want string // the access token the file holds after
|
|
|
|
|
}{
|
|
|
|
|
{"the start's first view, a login made while stopped", login, false, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
{"the start's first view, a login made while stopped", login, false, 0, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return FirstBinding(p, ask, w)
|
|
|
|
|
}, "at-login"},
|
|
|
|
|
{"binding.changed heard while it runs, before the grant was asked", login, false, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
{"binding.changed heard while it runs, before the grant was asked", login, false, 0, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return OnBindingChanged(p, []byte(`{"consumer":"laptop","licence":"personal","key":"personal","kind":"subscription","generation":9}`), ask, w)
|
|
|
|
|
}, "at-login"},
|
|
|
|
|
{"the vault's change heard while it runs, before the grant was asked", login, false, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
{"the vault's change heard while it runs, before the grant was asked", login, false, 0, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return OnSecretChanged(p, []byte(`{"name":"licence.personal.access","generation":5}`), ask, w)
|
|
|
|
|
}, "at-login"},
|
|
|
|
|
{"the successor of a login handed, of a newer lineage", login, true, 20000, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
{"a login handed, met by its refresh: same lineage, later access expiry (H-A-139)", login, true, 9000, now + 3*7_200_000, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return OnBindingChanged(p, []byte(`{"consumer":"laptop","licence":"personal","key":"personal","kind":"subscription","generation":9}`), ask, w)
|
|
|
|
|
}, "at-new"},
|
|
|
|
|
{"a login handed, met by a lease older than it (H-A-138)", login, true, 100, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
{"a login handed, met by a newer lineage (H-A-138)", login, true, 200_000_000, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return OnBindingChanged(p, []byte(`{"consumer":"laptop","licence":"personal","key":"personal","kind":"subscription","generation":9}`), ask, w)
|
|
|
|
|
}, "at-new"},
|
|
|
|
|
{"a login handed, met by the same lineage with an earlier access expiry (H-A-139)", login, true, 9000, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return OnBindingChanged(p, []byte(`{"consumer":"laptop","licence":"personal","key":"personal","kind":"subscription","generation":9}`), ask, w)
|
|
|
|
|
}, "at-login"},
|
|
|
|
|
{"a login handed, met by a lease with no lineage mark (H-A-138)", login, true, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
{"a login handed, met by the same lineage with an equal access expiry (H-A-139)", login, true, 9000, now + 7_200_000, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return OnBindingChanged(p, []byte(`{"consumer":"laptop","licence":"personal","key":"personal","kind":"subscription","generation":9}`), ask, w)
|
|
|
|
|
}, "at-login"},
|
|
|
|
|
{"a file holding the lease, older than the one handed", lease, false, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
{"a login handed, met by an older lineage (H-A-138)", login, true, -100_000_000, now + 3*7_200_000, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return OnBindingChanged(p, []byte(`{"consumer":"laptop","licence":"personal","key":"personal","kind":"subscription","generation":9}`), ask, w)
|
|
|
|
|
}, "at-login"},
|
|
|
|
|
{"a login handed, met by a lease with no lineage mark (H-A-138)", login, true, 0, now + 3*7_200_000, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return OnBindingChanged(p, []byte(`{"consumer":"laptop","licence":"personal","key":"personal","kind":"subscription","generation":9}`), ask, w)
|
|
|
|
|
}, "at-login"},
|
|
|
|
|
{"a file holding the lease, older than the one handed", lease, false, 0, 0, func(p Paths, ask Ask, w WriteManaged) (string, error) {
|
|
|
|
|
return FirstBinding(p, ask, w)
|
|
|
|
|
}, "at-new"},
|
|
|
|
|
} {
|
|
|
|
@@ -412,9 +422,17 @@ func TestALoginNotHandedIsNeverWrittenOverAndItsSuccessorReplacesIt(t *testing.T
|
|
|
|
|
if address == SeatVerb("bindings") {
|
|
|
|
|
return json.RawMessage(`[{"consumer":"laptop","licence":"personal","key":"personal","kind":"subscription","generation":9}]`), nil
|
|
|
|
|
}
|
|
|
|
|
if address == VaultGet && c.offeredRTE != 0 {
|
|
|
|
|
g, _ := json.Marshal(Grant{AccessToken: "at-new", ExpiresAt: now + 3_600_000, RefreshTokenExpiresAt: &c.offeredRTE})
|
|
|
|
|
box, err := Seal(string(g), args.(map[string]any)["public_key"].(string))
|
|
|
|
|
if address == VaultGet && (c.offeredRTE != 0 || c.offeredExp != 0) {
|
|
|
|
|
exp := c.offeredExp
|
|
|
|
|
if exp == 0 {
|
|
|
|
|
exp = now + 3_600_000
|
|
|
|
|
}
|
|
|
|
|
g := Grant{AccessToken: "at-new", ExpiresAt: exp}
|
|
|
|
|
if c.offeredRTE != 0 {
|
|
|
|
|
g.RefreshTokenExpiresAt = &c.offeredRTE
|
|
|
|
|
}
|
|
|
|
|
gj, _ := json.Marshal(g)
|
|
|
|
|
box, err := Seal(string(gj), args.(map[string]any)["public_key"].(string))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|