Skip to content

Commit 7ec4a90

Browse files
authored
Bug 1887958 - call disconnect from the AuthIssues state (#6976)
This works because a side effect of moving to the internal `Disconnect` state is calling the `disconnect()` method.
1 parent e1f2c7d commit 7ec4a90

File tree

1 file changed

+18
-2
lines changed
  • components/fxa-client/src/state_machine/internal_machines

1 file changed

+18
-2
lines changed

components/fxa-client/src/state_machine/internal_machines/auth_issues.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use super::{invalid_transition, Event, InternalStateMachine, State};
66
use crate::{Error, FxaEvent, FxaState, Result};
7+
use error_support::report_error;
78

89
pub struct AuthIssuesStateMachine;
910

@@ -18,13 +19,20 @@ impl InternalStateMachine for AuthIssuesStateMachine {
1819
scopes: scopes.clone(),
1920
entrypoint: entrypoint.clone(),
2021
}),
21-
FxaEvent::Disconnect => Ok(Complete(FxaState::Disconnected)),
22+
FxaEvent::Disconnect => Ok(Disconnect),
2223
e => Err(Error::InvalidStateTransition(format!("AuthIssues -> {e}"))),
2324
}
2425
}
2526

2627
fn next_state(&self, state: State, event: Event) -> Result<State> {
2728
Ok(match (state, event) {
29+
(Disconnect, DisconnectSuccess) => Complete(FxaState::Disconnected),
30+
(Disconnect, CallError) => {
31+
// disconnect() is currently infallible, but let's handle errors anyway in case we
32+
// refactor it in the future.
33+
report_error!("fxa-state-machine-error", "saw CallError after Disconnect");
34+
Complete(FxaState::Disconnected)
35+
}
2836
(BeginOAuthFlow { .. }, BeginOAuthFlowSuccess { oauth_url }) => {
2937
Complete(FxaState::Authenticating { oauth_url })
3038
}
@@ -70,6 +78,14 @@ mod test {
7078
#[test]
7179
fn test_disconnect() {
7280
let tester = StateMachineTester::new(AuthIssuesStateMachine, FxaEvent::Disconnect);
73-
assert_eq!(tester.state, Complete(FxaState::Disconnected));
81+
assert_eq!(tester.state, Disconnect);
82+
assert_eq!(
83+
tester.peek_next_state(CallError),
84+
Complete(FxaState::Disconnected)
85+
);
86+
assert_eq!(
87+
tester.peek_next_state(DisconnectSuccess),
88+
Complete(FxaState::Disconnected)
89+
);
7490
}
7591
}

0 commit comments

Comments
 (0)