@@ -337,6 +337,97 @@ func TestHandlers(t *testing.T) {
337337 require .Equal (t , prevPriv , bw .PrivateKey )
338338 })
339339
340+ t .Run ("CreateUserWithoutHashInForcedOIDCContext" , func (t * testing.T ) {
341+ setup := setUpRabbitMQConfig (t , MQ , "CreateUserWithoutHashInForcedOIDCContext" )
342+ cfg := config .GetConfig ()
343+ prevAuthentication := cfg .Authentication
344+ const oidcContext = "oidc-no-password-context"
345+ cfg .Authentication = map [string ]interface {}{
346+ oidcContext : map [string ]interface {}{
347+ "disable_password_authentication" : true ,
348+ },
349+ }
350+ t .Cleanup (func () {
351+ cfg .Authentication = prevAuthentication
352+ })
353+
354+ suffix := fmt .Sprintf ("%d" , time .Now ().UnixNano ())
355+ orgDomain := "no-hash-org-" + suffix + ".example"
356+ orgID := "org-no-hash-" + suffix
357+ targetEmail := "target-" + suffix + "@example.com"
358+ target := setup .GetTestInstance (& lifecycle.Options {
359+ Domain : "no-hash-target-" + suffix + ".local" ,
360+ ContextName : oidcContext ,
361+ OrgDomain : orgDomain ,
362+ OrgID : orgID ,
363+ Email : targetEmail ,
364+ PublicName : "Target User" ,
365+ })
366+ other := createInstanceInOrg (
367+ t ,
368+ "no-hash-other-" + suffix + ".local" ,
369+ orgDomain ,
370+ orgID ,
371+ "other-" + suffix + "@example.com" ,
372+ "Other User" ,
373+ )
374+
375+ initialHash := string (target .PassphraseHash )
376+ require .NotEmpty (t , initialHash )
377+ require .NotNil (t , target .PasswordDefined )
378+ require .False (t , * target .PasswordDefined )
379+
380+ ch , err := getChannel (t , MQ )
381+ require .NoError (t , err )
382+
383+ slug , _ := SplitDomain (t , target .Domain )
384+ msg := rabbitmq.UserCreatedMessage {
385+ TwakeID : slug ,
386+ Mobile : "+33700000000" ,
387+ InternalEmail : targetEmail ,
388+ Timestamp : time .Now ().Unix (),
389+ WorkplaceFqdn : target .Domain ,
390+ OrganizationID : orgID ,
391+ OrganizationDomain : orgDomain ,
392+ }
393+ body , err := json .Marshal (msg )
394+ require .NoError (t , err )
395+
396+ err = ch .PublishWithContext (
397+ testCtx (t ),
398+ "auth" ,
399+ "user.created" ,
400+ false ,
401+ false ,
402+ amqp.Publishing {
403+ DeliveryMode : amqp .Persistent ,
404+ ContentType : "application/json" ,
405+ Body : body ,
406+ MessageId : fmt .Sprintf ("%d" , time .Now ().UnixNano ()),
407+ },
408+ )
409+ require .NoError (t , err )
410+
411+ testutils .WaitForOrFail (t , 10 * time .Second , func () bool {
412+ matches , err := contact .FindAllByEmail (other , targetEmail )
413+ if err != nil {
414+ return false
415+ }
416+ for _ , doc := range matches {
417+ if doc .IsExternal () {
418+ return true
419+ }
420+ }
421+ return false
422+ })
423+
424+ updated , err := lifecycle .GetInstance (target .Domain )
425+ require .NoError (t , err )
426+ require .Equal (t , initialHash , string (updated .PassphraseHash ))
427+ require .NotNil (t , updated .PasswordDefined )
428+ require .False (t , * updated .PasswordDefined )
429+ })
430+
340431 t .Run ("DeleteUserHandler" , func (t * testing.T ) {
341432 setup := setUpRabbitMQConfig (t , MQ , "DeleteUserHandler" )
342433 _ = setup .GetTestInstance ()
0 commit comments