Skip to content

Commit

Permalink
pam/integration-tests/gdm: Try doing broker selection also on receive…
Browse files Browse the repository at this point in the history
…d brokers

We have a race on broker selection because we may choose a broker when
we don't have one yet, as this depends on the order of the events that
may not always be the same.

To prevent this:
 1. If received the brokers and we're in broker selection stage
    -> Do the broker selection right away, marking it as done
 2. If we just switched to broker selection stage
    a. If the brokers have been received, try to switch to the selected
       one or error if not found.
    b. If brokers have not yet been received, we just ignore the request
       and perform it once the brokers have been provided.

Partially go back to 48db852 logic.

See: https://github.com/ubuntu/authd/actions/runs/12144656077/job/33864519830
  • Loading branch information
3v1n0 committed Dec 3, 2024
1 parent 315214a commit 3d91da4
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pam/integration-tests/gdm-module-handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ func (gh *gdmTestModuleHandler) exampleHandleEvent(event *gdm.EventData) error {
}
gh.brokersInfos = ev.BrokersReceived.BrokersInfos

if gh.currentStage != proto.Stage_brokerSelection {
return nil
}
if gh.selectedBrokerName == ignoredBrokerName {
return nil
}
idx := slices.IndexFunc(gh.brokersInfos, func(bi *authd.ABResponse_BrokerInfo) bool {
return bi.Name == gh.selectedBrokerName
})
if idx < 0 {
return fmt.Errorf("broker %q is not known", gh.selectedBrokerName)
}

gh.pollResponses = append(gh.pollResponses,
gdm_test.SelectBrokerEvent(gh.brokersInfos[idx].Id))

case *gdm.EventData_BrokerSelected:
idx := slices.IndexFunc(gh.brokersInfos, func(broker *authd.ABResponse_BrokerInfo) bool {
return broker.Id == ev.BrokerSelected.BrokerId
Expand Down Expand Up @@ -219,11 +235,15 @@ func (gh *gdmTestModuleHandler) exampleHandleAuthDRequest(gdmData *gdm.Data) (*g
idx := slices.IndexFunc(gh.brokersInfos, func(bi *authd.ABResponse_BrokerInfo) bool {
return bi.Name == gh.selectedBrokerName
})
if idx < 0 {
if idx < 0 && len(gh.brokersInfos) > 0 {
return nil, fmt.Errorf("broker '%s' is not known", gh.selectedBrokerName)
}
if idx < 0 {
break
}

gh.pollResponses = append(gh.pollResponses, gdm_test.SelectBrokerEvent(gh.brokersInfos[idx].Id))
gh.selectedBrokerName = ignoredBrokerName

case proto.Stage_authModeSelection:
gh.currentUILayout = nil
Expand Down

0 comments on commit 3d91da4

Please sign in to comment.