1010
1111from cryptography .hazmat .backends import default_backend
1212from cryptography .hazmat .primitives import serialization
13- from cryptography .hazmat .primitives .asymmetric import ec
13+ from cryptography .hazmat .primitives .asymmetric import rsa
1414from django .contrib .auth .models import User
1515from django .test import override_settings
1616from rest_framework .test import APITestCase
@@ -175,7 +175,7 @@ class UserExternalTokenTest(GoAPITestCase):
175175
176176 def setUp (self ):
177177 super ().setUp ()
178- private_key = ec .generate_private_key (ec . SECP256R1 (), default_backend ())
178+ private_key = rsa .generate_private_key (public_exponent = 65537 , key_size = 4096 , backend = default_backend ())
179179 public_key = private_key .public_key ()
180180 private_key_pem = private_key .private_bytes (
181181 encoding = serialization .Encoding .PEM ,
@@ -185,11 +185,12 @@ def setUp(self):
185185
186186 # Serialize public key
187187 public_key_pem = public_key .public_bytes (
188- encoding = serialization .Encoding .PEM , format = serialization .PublicFormat .SubjectPublicKeyInfo
188+ encoding = serialization .Encoding .PEM ,
189+ format = serialization .PublicFormat .SubjectPublicKeyInfo ,
189190 )
190191
191- self .JWT_PRIVATE_KEY = private_key_pem .decode ("utf-8" )
192- self .JWT_PUBLIC_KEY = public_key_pem .decode ("utf-8" )
192+ self .OIDC_RSA_PRIVATE_KEY = private_key_pem .decode ("utf-8" )
193+ self .OIDC_RSA_PUBLIC_KEY = public_key_pem .decode ("utf-8" )
193194
194195 def test_external_token_with_key (self ):
195196 self .client .force_authenticate (self .user )
@@ -205,8 +206,8 @@ def test_external_token_with_key(self):
205206 data = {"title" : "ok" }
206207
207208 with override_settings (
208- JWT_PRIVATE_KEY = self .JWT_PRIVATE_KEY ,
209- JWT_PUBLIC_KEY = self .JWT_PUBLIC_KEY ,
209+ OIDC_RSA_PRIVATE_KEY = self .OIDC_RSA_PRIVATE_KEY ,
210+ OIDC_RSA_PUBLIC_KEY = self .OIDC_RSA_PUBLIC_KEY ,
210211 ):
211212 response = self .client .post ("/api/v2/external-token/" , data , format = "json" )
212213 self .assertEqual (response .status_code , 201 )
0 commit comments