@@ -107,6 +107,17 @@ def _raise_exception(st):
107107 TEST_OIDC_EXP_BASE ,
108108 _urlsafe_unpadded_b64encode (TEST_CLIENT_CERT )
109109])
110+ TEST_OIDC_CONTAINS_RESERVED_CHARACTERS = "." .join ([
111+ _urlsafe_unpadded_b64encode (TEST_OIDC_TOKEN ),
112+ _urlsafe_unpadded_b64encode (TEST_OIDC_INFO ).replace ("a" , "+" ),
113+ _urlsafe_unpadded_b64encode (TEST_CLIENT_CERT )
114+ ])
115+ TEST_OIDC_INVALID_PADDING_LENGTH = "." .join ([
116+ _urlsafe_unpadded_b64encode (TEST_OIDC_TOKEN ),
117+ "aaaaa" ,
118+ _urlsafe_unpadded_b64encode (TEST_CLIENT_CERT )
119+ ])
120+
110121TEST_OIDC_CA = _base64 (TEST_CERTIFICATE_AUTH )
111122
112123
@@ -394,6 +405,22 @@ class TestKubeConfigLoader(BaseTestCase):
394405 "user" : "expired_oidc_nocert"
395406 }
396407 },
408+ {
409+ "name" : "oidc_contains_reserved_character" ,
410+ "context" : {
411+ "cluster" : "default" ,
412+ "user" : "oidc_contains_reserved_character"
413+
414+ }
415+ },
416+ {
417+ "name" : "oidc_invalid_padding_length" ,
418+ "context" : {
419+ "cluster" : "default" ,
420+ "user" : "oidc_invalid_padding_length"
421+
422+ }
423+ },
397424 {
398425 "name" : "user_pass" ,
399426 "context" : {
@@ -556,6 +583,38 @@ class TestKubeConfigLoader(BaseTestCase):
556583 }
557584 }
558585 },
586+ {
587+ "name" : "oidc_contains_reserved_character" ,
588+ "user" : {
589+ "auth-provider" : {
590+ "name" : "oidc" ,
591+ "config" : {
592+ "client-id" : "tectonic-kubectl" ,
593+ "client-secret" : "FAKE_SECRET" ,
594+ "id-token" : TEST_OIDC_CONTAINS_RESERVED_CHARACTERS ,
595+ "idp-issuer-url" : "https://example.org/identity" ,
596+ "refresh-token" :
597+ "lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk"
598+ }
599+ }
600+ }
601+ },
602+ {
603+ "name" : "oidc_invalid_padding_length" ,
604+ "user" : {
605+ "auth-provider" : {
606+ "name" : "oidc" ,
607+ "config" : {
608+ "client-id" : "tectonic-kubectl" ,
609+ "client-secret" : "FAKE_SECRET" ,
610+ "id-token" : TEST_OIDC_INVALID_PADDING_LENGTH ,
611+ "idp-issuer-url" : "https://example.org/identity" ,
612+ "refresh-token" :
613+ "lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk"
614+ }
615+ }
616+ }
617+ },
559618 {
560619 "name" : "user_pass" ,
561620 "user" : {
@@ -712,6 +771,26 @@ def test_oidc_with_refresh_nocert(
712771 self .assertTrue (loader ._load_auth_provider_token ())
713772 self .assertEqual ("Bearer abc123" , loader .token )
714773
774+ def test_oidc_fails_if_contains_reserved_chars (self ):
775+ loader = KubeConfigLoader (
776+ config_dict = self .TEST_KUBE_CONFIG ,
777+ active_context = "oidc_contains_reserved_character" ,
778+ )
779+ self .assertEqual (
780+ loader ._load_oid_token ("oidc_contains_reserved_character" ),
781+ None ,
782+ )
783+
784+ def test_oidc_fails_if_invalid_padding_length (self ):
785+ loader = KubeConfigLoader (
786+ config_dict = self .TEST_KUBE_CONFIG ,
787+ active_context = "oidc_invalid_padding_length" ,
788+ )
789+ self .assertEqual (
790+ loader ._load_oid_token ("oidc_invalid_padding_length" ),
791+ None ,
792+ )
793+
715794 def test_user_pass (self ):
716795 expected = FakeConfig (host = TEST_HOST , token = TEST_BASIC_TOKEN )
717796 actual = FakeConfig ()
0 commit comments