-
Notifications
You must be signed in to change notification settings - Fork 103
sessions: strict state shifts #985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fa0dcab
to
f3b5393
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Niiiiiiiice, thanks for this 🙏!!
uTACK LGTM 🚀!
Leaving some docs and test coverage comments.
// Trying to shift the state from a terminal state back to StateCreated | ||
// should also fail since this is not a legal state transition. | ||
err = db.ShiftState(s1.ID, StateCreated) | ||
require.ErrorContains(t, err, "illegal session state transition") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
Would also be value in testing that shifting a StateReserved
session to StateRevoked
is not legal, as that's the concern in the comment that this PR is addressing :). Potentially also add coverage to show that StateInUse
-> StateRevoked
is legal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally, i think we only need to test illegal state transitions once and not for every possible iteration
f3b5393
to
ec8d136
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, LGTM 🎉
@@ -360,7 +360,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context, | |||
log.Debugf("Not resuming session %x with expiry %s", | |||
pubKeyBytes, sess.Expiry) | |||
|
|||
err := s.cfg.db.ShiftState(sess.ID, session.StateRevoked) | |||
err := s.cfg.db.ShiftState(sess.ID, session.StateExpired) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Addresses this comment.
In this PR, we ensure all session state shifts are legal via a strict transition map. We then replace the
RevokeSession method with a new ShiftState method. Finally, for expired sessions, we use the Expired state
instead of the Revoked state.