@@ -394,229 +394,6 @@ func TestUserMetadata_userMetadataSanitize(t *testing.T) {
394394 })
395395}
396396
397- func TestUser_PrepareForMetadataLookup (t * testing.T ) {
398- tests := []struct {
399- name string
400- input string
401- expectedCanonical bool
402- expectedSub string
403- expectedUserID string
404- expectedUsername string
405- }{
406- {
407- name : "canonical lookup with auth0 connection" ,
408- input : "auth0|123456789" ,
409- expectedCanonical : true ,
410- expectedSub : "auth0|123456789" ,
411- expectedUserID : "auth0|123456789" ,
412- expectedUsername : "" ,
413- },
414- {
415- name : "canonical lookup with google oauth2" ,
416- input : "google-oauth2|987654321" ,
417- expectedCanonical : true ,
418- expectedSub : "google-oauth2|987654321" ,
419- expectedUserID : "google-oauth2|987654321" ,
420- expectedUsername : "" ,
421- },
422- {
423- name : "canonical lookup with github connection" ,
424- input : "github|456789123" ,
425- expectedCanonical : true ,
426- expectedSub : "github|456789123" ,
427- expectedUserID : "github|456789123" ,
428- expectedUsername : "" ,
429- },
430- {
431- name : "canonical lookup with samlp enterprise" ,
432- input : "samlp|enterprise|user123" ,
433- expectedCanonical : true ,
434- expectedSub : "samlp|enterprise|user123" ,
435- expectedUserID : "samlp|enterprise|user123" ,
436- expectedUsername : "" ,
437- },
438- {
439- name : "canonical lookup with linkedin" ,
440- input : "linkedin|789123456" ,
441- expectedCanonical : true ,
442- expectedSub : "linkedin|789123456" ,
443- expectedUserID : "linkedin|789123456" ,
444- expectedUsername : "" ,
445- },
446- {
447- name : "search lookup with simple username" ,
448- input : "john.doe" ,
449- expectedCanonical : false ,
450- expectedSub : "" ,
451- expectedUserID : "" ,
452- expectedUsername : "john.doe" ,
453- },
454- {
455- name : "search lookup with complex username" ,
456- input : "jane.smith123" ,
457- expectedCanonical : false ,
458- expectedSub : "" ,
459- expectedUserID : "" ,
460- expectedUsername : "jane.smith123" ,
461- },
462- {
463- name : "search lookup with developer username" ,
464- input : "developer123" ,
465- expectedCanonical : false ,
466- expectedSub : "" ,
467- expectedUserID : "" ,
468- expectedUsername : "developer123" ,
469- },
470- {
471- name : "canonical lookup with spaces (trimmed)" ,
472- input : " auth0|123456789 " ,
473- expectedCanonical : true ,
474- expectedSub : "auth0|123456789" ,
475- expectedUserID : "auth0|123456789" ,
476- expectedUsername : "" ,
477- },
478- {
479- name : "search lookup with spaces (trimmed)" ,
480- input : " john.doe " ,
481- expectedCanonical : false ,
482- expectedSub : "" ,
483- expectedUserID : "" ,
484- expectedUsername : "john.doe" ,
485- },
486- {
487- name : "canonical lookup with pipe at start" ,
488- input : "|startpipe" ,
489- expectedCanonical : true ,
490- expectedSub : "|startpipe" ,
491- expectedUserID : "|startpipe" ,
492- expectedUsername : "" ,
493- },
494- {
495- name : "canonical lookup with pipe at end" ,
496- input : "endpipe|" ,
497- expectedCanonical : true ,
498- expectedSub : "endpipe|" ,
499- expectedUserID : "endpipe|" ,
500- expectedUsername : "" ,
501- },
502- {
503- name : "empty input (search strategy)" ,
504- input : "" ,
505- expectedCanonical : false ,
506- expectedSub : "" ,
507- expectedUserID : "" ,
508- expectedUsername : "" ,
509- },
510- }
511-
512- for _ , tt := range tests {
513- t .Run (tt .name , func (t * testing.T ) {
514- user := & User {}
515- result := user .PrepareForMetadataLookup (tt .input )
516-
517- // Check strategy result
518- if result != tt .expectedCanonical {
519- t .Errorf ("PrepareForMetadataLookup() returned %v, expected %v" , result , tt .expectedCanonical )
520- }
521-
522- // Check Sub field
523- if user .Sub != tt .expectedSub {
524- t .Errorf ("Sub = %q, expected %q" , user .Sub , tt .expectedSub )
525- }
526-
527- // Check UserID field
528- if user .UserID != tt .expectedUserID {
529- t .Errorf ("UserID = %q, expected %q" , user .UserID , tt .expectedUserID )
530- }
531-
532- // Check Username field
533- if user .Username != tt .expectedUsername {
534- t .Errorf ("Username = %q, expected %q" , user .Username , tt .expectedUsername )
535- }
536- })
537- }
538- }
539-
540- func TestUser_PrepareForMetadataLookup_Idempotency (t * testing.T ) {
541- // Test that calling PrepareForMetadataLookup multiple times with the same input
542- // produces the same result
543- user := & User {}
544-
545- // First call
546- result1 := user .PrepareForMetadataLookup ("auth0|123456789" )
547- sub1 , userID1 , username1 := user .Sub , user .UserID , user .Username
548-
549- // Second call with same input
550- result2 := user .PrepareForMetadataLookup ("auth0|123456789" )
551- sub2 , userID2 , username2 := user .Sub , user .UserID , user .Username
552-
553- // Results should be identical
554- if result1 != result2 {
555- t .Errorf ("PrepareForMetadataLookup() not idempotent: first=%v, second=%v" , result1 , result2 )
556- }
557- if sub1 != sub2 {
558- t .Errorf ("Sub not idempotent: first=%q, second=%q" , sub1 , sub2 )
559- }
560- if userID1 != userID2 {
561- t .Errorf ("UserID not idempotent: first=%q, second=%q" , userID1 , userID2 )
562- }
563- if username1 != username2 {
564- t .Errorf ("Username not idempotent: first=%q, second=%q" , username1 , username2 )
565- }
566- }
567-
568- func TestUser_PrepareForMetadataLookup_StrategySwitch (t * testing.T ) {
569- // Test that switching between strategies properly clears the other fields
570- user := & User {}
571-
572- // Start with canonical lookup
573- canonical := user .PrepareForMetadataLookup ("auth0|123456789" )
574- if ! canonical {
575- t .Fatal ("Expected canonical strategy" )
576- }
577- if user .Sub == "" || user .UserID == "" || user .Username != "" {
578- t .Errorf ("Canonical strategy fields not set correctly: Sub=%q, UserID=%q, Username=%q" ,
579- user .Sub , user .UserID , user .Username )
580- }
581-
582- // Switch to search lookup
583- search := user .PrepareForMetadataLookup ("john.doe" )
584- if search {
585- t .Fatal ("Expected search strategy" )
586- }
587- if user .Sub != "" || user .UserID != "" || user .Username == "" {
588- t .Errorf ("Search strategy fields not set correctly: Sub=%q, UserID=%q, Username=%q" ,
589- user .Sub , user .UserID , user .Username )
590- }
591- }
592-
593- func TestUser_PrepareForMetadataLookup_PreservesOtherFields (t * testing.T ) {
594- // Test that PrepareForMetadataLookup doesn't modify other user fields
595- user := & User {
596- Token : "test-token" ,
597- PrimaryEmail : "test@example.com" ,
598- UserMetadata : & UserMetadata {
599- Name : converters .StringPtr ("Test User" ),
600- },
601- }
602-
603- originalToken := user .Token
604- originalEmail := user .PrimaryEmail
605- originalMetadata := user .UserMetadata
606-
607- user .PrepareForMetadataLookup ("auth0|123456789" )
608-
609- if user .Token != originalToken {
610- t .Errorf ("Token was modified: got %q, expected %q" , user .Token , originalToken )
611- }
612- if user .PrimaryEmail != originalEmail {
613- t .Errorf ("PrimaryEmail was modified: got %q, expected %q" , user .PrimaryEmail , originalEmail )
614- }
615- if user .UserMetadata != originalMetadata {
616- t .Errorf ("UserMetadata was modified" )
617- }
618- }
619-
620397func TestUser_buildIndexKey (t * testing.T ) {
621398 tests := []struct {
622399 name string
0 commit comments