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