Skip to content

Commit

Permalink
pam/nativemodel: Add more debug info to check stage changes
Browse files Browse the repository at this point in the history
It may help debugging ubuntu#719
  • Loading branch information
3v1n0 committed Feb 27, 2025
1 parent 0fadf0f commit 12565bd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pam/internal/adapter/nativemodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ func (m nativeModel) changeStage(stage proto.Stage) tea.Cmd {
return sendEvent(nativeChangeStage{stage})
}

func (m nativeModel) checkStage(expected proto.Stage) bool {
if m.currentStage != expected {
log.Debugf(context.Background(),
"Current stage %q is not matching expected %q", m.currentStage, expected)
return false
}
return true
}

func (m nativeModel) requestStageChange(stage proto.Stage) tea.Cmd {
return sendEvent(nativeStageChangeRequest{stage})
}
Expand Down Expand Up @@ -179,7 +188,7 @@ func (m nativeModel) Update(msg tea.Msg) (nativeModel, tea.Cmd) {
return m, m.requestStageChange(pam_proto.Stage_userSelection)

case nativeUserSelection:
if m.currentStage != proto.Stage_userSelection {
if !m.checkStage(proto.Stage_userSelection) {
return m, nil
}
if m.busy {
Expand Down Expand Up @@ -227,7 +236,7 @@ func (m nativeModel) Update(msg tea.Msg) (nativeModel, tea.Cmd) {
})

case nativeBrokerSelection:
if m.currentStage != proto.Stage_brokerSelection {
if !m.checkStage(proto.Stage_brokerSelection) {
return m, nil
}
if m.busy {
Expand All @@ -251,7 +260,7 @@ func (m nativeModel) Update(msg tea.Msg) (nativeModel, tea.Cmd) {
return m.startAsyncOp(m.brokerSelection)

case nativeAuthSelection:
if m.currentStage != proto.Stage_authModeSelection {
if !m.checkStage(proto.Stage_authModeSelection) {
return m, nil
}
if m.busy {
Expand Down Expand Up @@ -286,7 +295,7 @@ func (m nativeModel) Update(msg tea.Msg) (nativeModel, tea.Cmd) {
return m, m.requestStageChange(pam_proto.Stage_challenge)

case nativeChallengeRequested:
if m.currentStage != pam_proto.Stage_challenge {
if !m.checkStage(pam_proto.Stage_challenge) {
return m, nil
}
return m, m.startChallenge()
Expand Down

0 comments on commit 12565bd

Please sign in to comment.