@@ -629,3 +629,88 @@ def test_default_values(self):
629629 self .assertEqual (ds .search_endpoint , "/registry/sync/search" )
630630 self .assertEqual (ds .subscribe_endpoint , "/registry/subscribe" )
631631 self .assertEqual (ds .auth_endpoint , "/oauth2/client/token" )
632+
633+ def test_secret_display_field_masks_value (self ):
634+ """Test that oauth2_client_secret_display returns masked value"""
635+ ds = self .DataSource .create (
636+ {
637+ "name" : "Test CRVS" ,
638+ "code" : "test_crvs_mask" ,
639+ "base_url" : "https://crvs.example.org/api" ,
640+ "auth_type" : "oauth2" ,
641+ "oauth2_token_url" : "https://auth.example.org/token" ,
642+ "oauth2_client_id" : "client123" ,
643+ "oauth2_client_secret" : "secret456" ,
644+ "our_sender_id" : "openspp.example.org" ,
645+ }
646+ )
647+ # Display field should show mask, stored field should have real value
648+ self .assertEqual (ds .oauth2_client_secret_display , "********" )
649+ self .assertEqual (ds .oauth2_client_secret , "secret456" )
650+
651+ def test_secret_display_field_empty_when_no_secret (self ):
652+ """Test that oauth2_client_secret_display is empty when no secret is set"""
653+ ds = self .DataSource .create (
654+ {
655+ "name" : "Test CRVS" ,
656+ "code" : "test_crvs_empty" ,
657+ "base_url" : "https://crvs.example.org/api" ,
658+ "auth_type" : "none" ,
659+ }
660+ )
661+ self .assertFalse (ds .oauth2_client_secret_display )
662+ self .assertFalse (ds .oauth2_client_secret )
663+
664+ def test_secret_display_write_updates_stored_field (self ):
665+ """Test that writing a new value through display field updates the stored secret"""
666+ ds = self .DataSource .create (
667+ {
668+ "name" : "Test CRVS" ,
669+ "code" : "test_crvs_write" ,
670+ "base_url" : "https://crvs.example.org/api" ,
671+ "auth_type" : "oauth2" ,
672+ "oauth2_token_url" : "https://auth.example.org/token" ,
673+ "oauth2_client_id" : "client123" ,
674+ "oauth2_client_secret" : "old_secret" ,
675+ "our_sender_id" : "openspp.example.org" ,
676+ }
677+ )
678+ # Write a new secret through the display field
679+ ds .write ({"oauth2_client_secret_display" : "brand_new_secret" })
680+ self .assertEqual (ds .oauth2_client_secret , "brand_new_secret" )
681+ # Invalidate cache to force recomputation of the display field
682+ ds .invalidate_recordset (["oauth2_client_secret_display" ])
683+ self .assertEqual (ds .oauth2_client_secret_display , "********" )
684+
685+ def test_secret_display_mask_value_does_not_overwrite (self ):
686+ """Test that writing the mask value does not overwrite the real secret"""
687+ ds = self .DataSource .create (
688+ {
689+ "name" : "Test CRVS" ,
690+ "code" : "test_crvs_nooverwrite" ,
691+ "base_url" : "https://crvs.example.org/api" ,
692+ "auth_type" : "oauth2" ,
693+ "oauth2_token_url" : "https://auth.example.org/token" ,
694+ "oauth2_client_id" : "client123" ,
695+ "oauth2_client_secret" : "real_secret_value" ,
696+ "our_sender_id" : "openspp.example.org" ,
697+ }
698+ )
699+ # Writing the mask value should not change the stored secret
700+ ds .write ({"oauth2_client_secret_display" : "********" })
701+ self .assertEqual (ds .oauth2_client_secret , "real_secret_value" )
702+
703+ def test_secret_display_clear_removes_secret (self ):
704+ """Test that clearing the display field removes the stored secret"""
705+ ds = self .DataSource .create (
706+ {
707+ "name" : "Test CRVS" ,
708+ "code" : "test_crvs_clear" ,
709+ "base_url" : "https://crvs.example.org/api" ,
710+ "auth_type" : "none" ,
711+ "oauth2_client_secret" : "secret_to_clear" ,
712+ }
713+ )
714+ # Clear the secret through the display field
715+ ds .write ({"oauth2_client_secret_display" : False })
716+ self .assertFalse (ds .oauth2_client_secret )
0 commit comments