@@ -180,6 +180,15 @@ def test_status_and_logout(monkeypatch) -> None:
180180
181181
182182def test_select_certificate_and_require_non_empty_errors () -> None :
183+ cert = manager ._select_certificate (
184+ [
185+ {"usage" : ["KsefTokenEncryption" ], "certificate" : "" },
186+ {"usage" : ["KsefTokenEncryption" ], "certificate" : "CERT" },
187+ ],
188+ "KsefTokenEncryption" ,
189+ )
190+ assert cert == "CERT"
191+
183192 with pytest .raises (CliError ) as cert_error :
184193 manager ._select_certificate ([], "KsefTokenEncryption" )
185194 assert cert_error .value .code == ExitCode .API_ERROR
@@ -214,10 +223,31 @@ def test_resolve_base_url_uses_profile_when_missing(monkeypatch) -> None:
214223 assert manager .resolve_base_url (None , profile = "demo" ) == "https://profile.example"
215224
216225
226+ def test_resolve_base_url_falls_back_when_profile_base_url_empty (monkeypatch ) -> None :
227+ monkeypatch .setattr (
228+ manager ,
229+ "load_config" ,
230+ lambda : CliConfig (
231+ active_profile = "demo" ,
232+ profiles = {
233+ "demo" : ProfileConfig (
234+ name = "demo" ,
235+ env = "DEMO" ,
236+ base_url = " " ,
237+ context_type = "nip" ,
238+ context_value = "123" ,
239+ )
240+ },
241+ ),
242+ )
243+ assert manager .resolve_base_url (None , profile = "demo" ) == manager .KsefEnvironment .DEMO .value
244+
245+
217246def test_resolve_lighthouse_base_url_prefers_explicit_value () -> None :
218- assert manager .resolve_lighthouse_base_url (" https://api-latarnia-test.ksef.mf.gov.pl/ " ) == (
219- "https://api-latarnia-test.ksef.mf.gov.pl/"
220- ).strip ()
247+ assert (
248+ manager .resolve_lighthouse_base_url (" https://api-latarnia-test.ksef.mf.gov.pl/ " )
249+ == ("https://api-latarnia-test.ksef.mf.gov.pl/" ).strip ()
250+ )
221251
222252
223253def test_resolve_lighthouse_base_url_uses_profile_mapping (monkeypatch ) -> None :
@@ -269,6 +299,28 @@ def test_resolve_lighthouse_base_url_invalid_profile_base_fallback(monkeypatch)
269299 )
270300
271301
302+ def test_resolve_lighthouse_base_url_fallback_when_profile_base_url_empty (monkeypatch ) -> None :
303+ monkeypatch .setattr (
304+ manager ,
305+ "load_config" ,
306+ lambda : CliConfig (
307+ active_profile = "demo" ,
308+ profiles = {
309+ "demo" : ProfileConfig (
310+ name = "demo" ,
311+ env = "DEMO" ,
312+ base_url = " " ,
313+ context_type = "nip" ,
314+ context_value = "123" ,
315+ )
316+ },
317+ ),
318+ )
319+ assert manager .resolve_lighthouse_base_url (None , profile = "demo" ) == (
320+ KsefLighthouseEnvironment .TEST .value
321+ )
322+
323+
272324def test_refresh_access_token_missing_token_in_response (monkeypatch ) -> None :
273325 class _FakeClientNoToken :
274326 def __init__ (self ) -> None :
@@ -492,3 +544,60 @@ def test_login_with_xades_loader_errors_are_mapped(monkeypatch) -> None:
492544 save = False ,
493545 )
494546 assert exc .value .code == ExitCode .VALIDATION_ERROR
547+
548+
549+ def test_login_with_token_without_save (monkeypatch ) -> None :
550+ monkeypatch .setattr (manager , "create_client" , lambda base_url : _FakeClient ())
551+ monkeypatch .setattr (manager , "AuthCoordinator" , _FakeAuthCoordinator )
552+ monkeypatch .setattr (
553+ manager ,
554+ "save_tokens" ,
555+ lambda * args , ** kwargs : (_ for _ in ()).throw (
556+ AssertionError ("save_tokens should not be called" )
557+ ),
558+ )
559+ monkeypatch .setattr (
560+ manager ,
561+ "set_cached_metadata" ,
562+ lambda * args , ** kwargs : (_ for _ in ()).throw (
563+ AssertionError ("set_cached_metadata should not be called" )
564+ ),
565+ )
566+
567+ result = manager .login_with_token (
568+ profile = "demo" ,
569+ base_url = "https://api-demo.ksef.mf.gov.pl" ,
570+ token = "TOKEN" ,
571+ context_type = "nip" ,
572+ context_value = "5265877635" ,
573+ poll_interval = 0.0 ,
574+ max_attempts = 1 ,
575+ save = False ,
576+ )
577+ assert result ["saved" ] is False
578+
579+
580+ def test_refresh_access_token_success_without_save (monkeypatch ) -> None :
581+ monkeypatch .setattr (manager , "get_tokens" , lambda profile : ("acc" , "ref" ))
582+ monkeypatch .setattr (manager , "create_client" , lambda base_url : _FakeClient ())
583+ monkeypatch .setattr (
584+ manager ,
585+ "save_tokens" ,
586+ lambda * args , ** kwargs : (_ for _ in ()).throw (
587+ AssertionError ("save_tokens should not be called" )
588+ ),
589+ )
590+ monkeypatch .setattr (
591+ manager ,
592+ "set_cached_metadata" ,
593+ lambda * args , ** kwargs : (_ for _ in ()).throw (
594+ AssertionError ("set_cached_metadata should not be called" )
595+ ),
596+ )
597+
598+ result = manager .refresh_access_token (
599+ profile = "demo" ,
600+ base_url = "https://api-demo.ksef.mf.gov.pl" ,
601+ save = False ,
602+ )
603+ assert result ["saved" ] is False
0 commit comments