@@ -193,6 +193,82 @@ func (suite *OAuthExecutorTestSuite) TestBuildAuthorizeFlow_IDPNotConfigured() {
193193 assert .Contains (suite .T (), err .Error (), "idpId is not configured" )
194194}
195195
196+ func (suite * OAuthExecutorTestSuite ) TestProcessAuthFlowResponse_EmailMismatch_Fails () { //nolint:dupl
197+ ctx := & core.NodeContext {
198+ ExecutionID : "flow-123" ,
199+ FlowType : common .FlowTypeRegistration ,
200+ UserInputs : map [string ]string {
201+ "code" : "auth_code_123" ,
202+ "email" : "invited@example.com" ,
203+ },
204+ NodeProperties : map [string ]interface {}{
205+ "idpId" : "idp-123" ,
206+ },
207+ }
208+
209+ execResp := & common.ExecutorResponse {
210+ AdditionalData : make (map [string ]string ),
211+ RuntimeData : make (map [string ]string ),
212+ }
213+
214+ suite .mockAuthnProvider .On ("AuthenticateUser" , mock .Anything , mock .Anything , mock .Anything ,
215+ mock .Anything , mock .Anything , mock .Anything ).
216+ Return (authnprovidermgr.AuthUser {}, & authnprovidermgr.AuthnBasicResult {
217+ ExternalSub : "user-sub-123" ,
218+ ExternalClaims : map [string ]interface {}{
219+ "sub" : "user-sub-123" ,
220+ "email" : "authenticated@example.com" ,
221+ },
222+ IsExistingUser : false ,
223+ }, (* serviceerror .ServiceError )(nil ))
224+
225+ err := suite .executor .ProcessAuthFlowResponse (ctx , execResp )
226+
227+ assert .NoError (suite .T (), err )
228+ assert .Equal (suite .T (), common .ExecFailure , execResp .Status )
229+ assert .Equal (suite .T (), "Invalid federated user" , execResp .FailureReason )
230+ suite .mockAuthnProvider .AssertExpectations (suite .T ())
231+ }
232+
233+ func (suite * OAuthExecutorTestSuite ) TestProcessAuthFlowResponse_SubMismatch_Fails () { //nolint:dupl
234+ ctx := & core.NodeContext {
235+ ExecutionID : "flow-123" ,
236+ FlowType : common .FlowTypeRegistration ,
237+ UserInputs : map [string ]string {
238+ "code" : "auth_code_123" ,
239+ },
240+ RuntimeData : map [string ]string {
241+ "sub" : "stored-sub-123" ,
242+ },
243+ NodeProperties : map [string ]interface {}{
244+ "idpId" : "idp-123" ,
245+ },
246+ }
247+
248+ execResp := & common.ExecutorResponse {
249+ AdditionalData : make (map [string ]string ),
250+ RuntimeData : make (map [string ]string ),
251+ }
252+
253+ suite .mockAuthnProvider .On ("AuthenticateUser" , mock .Anything , mock .Anything , mock .Anything ,
254+ mock .Anything , mock .Anything , mock .Anything ).
255+ Return (authnprovidermgr.AuthUser {}, & authnprovidermgr.AuthnBasicResult {
256+ ExternalSub : "authenticated-sub-456" ,
257+ ExternalClaims : map [string ]interface {}{
258+ "sub" : "authenticated-sub-456" ,
259+ "email" : "user@example.com" ,
260+ },
261+ IsExistingUser : false ,
262+ }, (* serviceerror .ServiceError )(nil ))
263+
264+ err := suite .executor .ProcessAuthFlowResponse (ctx , execResp )
265+
266+ assert .NoError (suite .T (), err )
267+ assert .Equal (suite .T (), common .ExecFailure , execResp .Status )
268+ assert .Equal (suite .T (), "Invalid federated user" , execResp .FailureReason )
269+ suite .mockAuthnProvider .AssertExpectations (suite .T ())
270+ }
271+
196272func (suite * OAuthExecutorTestSuite ) TestBuildAuthorizeFlow_BuildURLClientError () {
197273 ctx := & core.NodeContext {
198274 ExecutionID : "flow-123" ,
0 commit comments