@@ -114,6 +114,17 @@ def _raise_exception(st):
114
114
TEST_OIDC_EXP_BASE ,
115
115
_urlsafe_unpadded_b64encode (TEST_CLIENT_CERT )
116
116
])
117
+ TEST_OIDC_CONTAINS_RESERVED_CHARACTERS = "." .join ([
118
+ _urlsafe_unpadded_b64encode (TEST_OIDC_TOKEN ),
119
+ _urlsafe_unpadded_b64encode (TEST_OIDC_INFO ).replace ("a" , "+" ),
120
+ _urlsafe_unpadded_b64encode (TEST_CLIENT_CERT )
121
+ ])
122
+ TEST_OIDC_INVALID_PADDING_LENGTH = "." .join ([
123
+ _urlsafe_unpadded_b64encode (TEST_OIDC_TOKEN ),
124
+ "aaaaa" ,
125
+ _urlsafe_unpadded_b64encode (TEST_CLIENT_CERT )
126
+ ])
127
+
117
128
TEST_OIDC_CA = _base64 (TEST_CERTIFICATE_AUTH )
118
129
119
130
@@ -420,6 +431,22 @@ class TestKubeConfigLoader(BaseTestCase):
420
431
"user" : "expired_oidc_nocert"
421
432
}
422
433
},
434
+ {
435
+ "name" : "oidc_contains_reserved_character" ,
436
+ "context" : {
437
+ "cluster" : "default" ,
438
+ "user" : "oidc_contains_reserved_character"
439
+
440
+ }
441
+ },
442
+ {
443
+ "name" : "oidc_invalid_padding_length" ,
444
+ "context" : {
445
+ "cluster" : "default" ,
446
+ "user" : "oidc_invalid_padding_length"
447
+
448
+ }
449
+ },
423
450
{
424
451
"name" : "user_pass" ,
425
452
"context" : {
@@ -606,6 +633,38 @@ class TestKubeConfigLoader(BaseTestCase):
606
633
}
607
634
}
608
635
},
636
+ {
637
+ "name" : "oidc_contains_reserved_character" ,
638
+ "user" : {
639
+ "auth-provider" : {
640
+ "name" : "oidc" ,
641
+ "config" : {
642
+ "client-id" : "tectonic-kubectl" ,
643
+ "client-secret" : "FAKE_SECRET" ,
644
+ "id-token" : TEST_OIDC_CONTAINS_RESERVED_CHARACTERS ,
645
+ "idp-issuer-url" : "https://example.org/identity" ,
646
+ "refresh-token" :
647
+ "lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk"
648
+ }
649
+ }
650
+ }
651
+ },
652
+ {
653
+ "name" : "oidc_invalid_padding_length" ,
654
+ "user" : {
655
+ "auth-provider" : {
656
+ "name" : "oidc" ,
657
+ "config" : {
658
+ "client-id" : "tectonic-kubectl" ,
659
+ "client-secret" : "FAKE_SECRET" ,
660
+ "id-token" : TEST_OIDC_INVALID_PADDING_LENGTH ,
661
+ "idp-issuer-url" : "https://example.org/identity" ,
662
+ "refresh-token" :
663
+ "lucWJjEhlxZW01cXI3YmVlcYnpxNGhzk"
664
+ }
665
+ }
666
+ }
667
+ },
609
668
{
610
669
"name" : "user_pass" ,
611
670
"user" : {
@@ -804,6 +863,26 @@ def test_oidc_with_refresh_nocert(
804
863
self .assertTrue (loader ._load_auth_provider_token ())
805
864
self .assertEqual ("Bearer abc123" , loader .token )
806
865
866
+ def test_oidc_fails_if_contains_reserved_chars (self ):
867
+ loader = KubeConfigLoader (
868
+ config_dict = self .TEST_KUBE_CONFIG ,
869
+ active_context = "oidc_contains_reserved_character" ,
870
+ )
871
+ self .assertEqual (
872
+ loader ._load_oid_token ("oidc_contains_reserved_character" ),
873
+ None ,
874
+ )
875
+
876
+ def test_oidc_fails_if_invalid_padding_length (self ):
877
+ loader = KubeConfigLoader (
878
+ config_dict = self .TEST_KUBE_CONFIG ,
879
+ active_context = "oidc_invalid_padding_length" ,
880
+ )
881
+ self .assertEqual (
882
+ loader ._load_oid_token ("oidc_invalid_padding_length" ),
883
+ None ,
884
+ )
885
+
807
886
def test_user_pass (self ):
808
887
expected = FakeConfig (host = TEST_HOST , token = TEST_BASIC_TOKEN )
809
888
actual = FakeConfig ()
0 commit comments