<s> """<STR_LIT>""" <EOL> import datetime <EOL> import os <EOL> from uuid import uuid4 , UUID <EOL> from Crypto . Util import asn1 <EOL> from OpenSSL import crypto <EOL> from twisted . python . filepath import FilePath <EOL> from . . import ( RootCredential , ControlCredential , NodeCredential , <EOL> UserCredential , PathError , EXPIRY_20_YEARS , <EOL> AUTHORITY_CERTIFICATE_FILENAME , AUTHORITY_KEY_FILENAME ) <EOL> from . . testtools import assert_has_extension <EOL> from ... testtools import not_root , skip_on_broken_permissions , TestCase <EOL> NODE_UUID = str ( uuid4 ( ) ) <EOL> def make_credential_tests ( cls , expected_file_name , ** kwargs ) : <EOL> class CredentialTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( CredentialTests , self ) . setUp ( ) <EOL> self . start_date = datetime . datetime . utcnow ( ) <EOL> self . expiry_date = self . start_date + datetime . timedelta ( <EOL> seconds = EXPIRY_20_YEARS ) <EOL> self . cert_file_name = expected_file_name + b"<STR_LIT>" <EOL> self . key_file_name = expected_file_name + b"<STR_LIT>" <EOL> self . path = FilePath ( self . mktemp ( ) ) <EOL> self . path . makedirs ( ) <EOL> self . ca = RootCredential . initialize ( <EOL> self . path , b"<STR_LIT>" , begin = self . start_date <EOL> ) <EOL> self . credential = cls . initialize ( <EOL> self . path , self . ca , begin = self . start_date , ** kwargs <EOL> ) <EOL> for k , v in kwargs . iteritems ( ) : <EOL> setattr ( self , k , v ) <EOL> def test_certificate_matches_public_key ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( <EOL> self . credential . credential . keypair . keypair . matches ( <EOL> self . credential . credential . certificate . getPublicKey ( ) ) <EOL> ) <EOL> def test_certificate_matches_private_key ( self ) : <EOL> """<STR_LIT>""" <EOL> priv = self . credential . credential . keypair . keypair . original <EOL> pub = self . credential . credential . certificate <EOL> pub = pub . getPublicKey ( ) . original <EOL> pub_asn1 = crypto . dump_privatekey ( crypto . FILETYPE_ASN1 , pub ) <EOL> priv_asn1 = crypto . dump_privatekey ( crypto . FILETYPE_ASN1 , priv ) <EOL> pub_der = asn1 . DerSequence ( ) <EOL> pub_der . decode ( pub_asn1 ) <EOL> priv_der = asn1 . DerSequence ( ) <EOL> priv_der . decode ( priv_asn1 ) <EOL> pub_modulus = pub_der [ <NUM_LIT:1> ] <EOL> priv_modulus = priv_der [ <NUM_LIT:1> ] <EOL> self . assertEqual ( pub_modulus , priv_modulus ) <EOL> def test_written_keypair_reloads ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . credential , <EOL> cls . from_path ( self . path , ** kwargs ) <EOL> ) <EOL> def test_create_error_on_non_existent_path ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> e = self . assertRaises ( <EOL> PathError , cls . initialize , <EOL> path , self . ca , ** kwargs <EOL> ) <EOL> expected = ( b"<STR_LIT>" <EOL> b"<STR_LIT>" ) . format ( <EOL> path = path . child ( self . cert_file_name ) . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> def test_load_error_on_non_existent_path ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> e = self . assertRaises ( <EOL> PathError , cls . from_path , <EOL> path , ** kwargs <EOL> ) <EOL> expected = ( b"<STR_LIT>" <EOL> b"<STR_LIT>" ) . format ( <EOL> path = path . child ( self . cert_file_name ) . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> def test_load_error_on_non_existent_certificate_file ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> e = self . assertRaises ( <EOL> PathError , cls . from_path , <EOL> path , ** kwargs <EOL> ) <EOL> expected = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> path = path . child ( self . cert_file_name ) . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> def test_load_error_on_non_existent_key_file ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> crt_path = path . child ( self . cert_file_name ) <EOL> crt_file = crt_path . open ( b'<STR_LIT:w>' ) <EOL> crt_file . write ( self . credential . credential . certificate . dumpPEM ( ) ) <EOL> crt_file . close ( ) <EOL> e = self . assertRaises ( <EOL> PathError , cls . from_path , <EOL> path , ** kwargs <EOL> ) <EOL> expected = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> path = path . child ( self . key_file_name ) . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> @ not_root <EOL> @ skip_on_broken_permissions <EOL> def test_load_error_on_unreadable_certificate_file ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> crt_path = path . child ( self . cert_file_name ) <EOL> crt_file = crt_path . open ( b'<STR_LIT:w>' ) <EOL> crt_file . write ( b"<STR_LIT>" ) <EOL> crt_file . close ( ) <EOL> crt_path . chmod ( <NUM_LIT> ) <EOL> key_path = path . child ( self . key_file_name ) <EOL> key_file = key_path . open ( b'<STR_LIT:w>' ) <EOL> key_file . write ( b"<STR_LIT>" ) <EOL> key_file . close ( ) <EOL> key_path . chmod ( <NUM_LIT> ) <EOL> e = self . assertRaises ( <EOL> PathError , cls . from_path , <EOL> path , ** kwargs <EOL> ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( path = crt_path . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> @ not_root <EOL> @ skip_on_broken_permissions <EOL> def test_load_error_on_unreadable_key_file ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> crt_path = path . child ( self . cert_file_name ) <EOL> crt_file = crt_path . open ( b'<STR_LIT:w>' ) <EOL> crt_file . write ( self . credential . credential . certificate . dumpPEM ( ) ) <EOL> crt_file . close ( ) <EOL> key_path = path . child ( self . key_file_name ) <EOL> key_file = key_path . open ( b'<STR_LIT:w>' ) <EOL> key_file . write ( b"<STR_LIT>" ) <EOL> key_file . close ( ) <EOL> key_path . chmod ( <NUM_LIT> ) <EOL> e = self . assertRaises ( <EOL> PathError , cls . from_path , <EOL> path , ** kwargs <EOL> ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( path = key_path . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> def test_certificate_ou_matches_ca ( self ) : <EOL> """<STR_LIT>""" <EOL> cert = self . credential . credential . certificate . original <EOL> issuer = cert . get_issuer ( ) <EOL> subject = cert . get_subject ( ) <EOL> self . assertEqual ( <EOL> issuer . OU , <EOL> subject . OU <EOL> ) <EOL> def test_certificate_is_signed_by_ca ( self ) : <EOL> """<STR_LIT>""" <EOL> cert = self . credential . credential . certificate . original <EOL> issuer = cert . get_issuer ( ) <EOL> self . assertEqual ( <EOL> issuer . CN , <EOL> self . ca . credential . certificate . getSubject ( ) . CN <EOL> ) <EOL> def test_certificate_expiration ( self ) : <EOL> """<STR_LIT>""" <EOL> cert = self . credential . credential . certificate . original <EOL> date_str = cert . get_notAfter ( ) <EOL> expected_expiry = self . expiry_date . strftime ( "<STR_LIT>" ) <EOL> self . assertEqual ( date_str , expected_expiry ) <EOL> def test_certificate_is_rsa_4096_sha_256 ( self ) : <EOL> """<STR_LIT>""" <EOL> cert = self . credential . credential . certificate . original <EOL> key = self . credential . credential . certificate <EOL> key = key . getPublicKey ( ) . original <EOL> self . assertEqual ( <EOL> ( crypto . TYPE_RSA , <NUM_LIT> , b'<STR_LIT>' ) , <EOL> ( key . type ( ) , key . bits ( ) , cert . get_signature_algorithm ( ) ) <EOL> ) <EOL> def test_keypair_correct_umask ( self ) : <EOL> """<STR_LIT>""" <EOL> key_path = self . path . child ( self . key_file_name ) <EOL> st = os . stat ( key_path . path ) <EOL> self . assertEqual ( b'<STR_LIT>' , oct ( st . st_mode & <NUM_LIT:0> <NUM_LIT> ) ) <EOL> def test_certificate_correct_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> cert_path = self . path . child ( self . cert_file_name ) <EOL> st = os . stat ( cert_path . path ) <EOL> self . assertEqual ( b'<STR_LIT>' , oct ( st . st_mode & <NUM_LIT:0> <NUM_LIT> ) ) <EOL> def test_written_keypair_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> ( True , True ) , <EOL> ( self . path . child ( self . cert_file_name ) . exists ( ) , <EOL> self . path . child ( self . key_file_name ) . exists ( ) ) <EOL> ) <EOL> return CredentialTests <EOL> class UserCredentialTests ( <EOL> make_credential_tests ( UserCredential , b"<STR_LIT>" , username = u"<STR_LIT>" ) ) : <EOL> """<STR_LIT>""" <EOL> def test_certificate_subject_username ( self ) : <EOL> """<STR_LIT>""" <EOL> cert = self . credential . credential . certificate . original <EOL> subject = cert . get_subject ( ) <EOL> self . assertEqual ( subject . CN , u"<STR_LIT>" . format ( <EOL> user = self . credential . username ) ) <EOL> def test_extendedKeyUsage ( self ) : <EOL> """<STR_LIT>""" <EOL> assert_has_extension ( self , self . credential . credential , <EOL> b"<STR_LIT>" , b"<STR_LIT>" ) <EOL> def test_from_files ( self ) : <EOL> """<STR_LIT>""" <EOL> certificate_path = self . credential . credential . path . child ( b"<STR_LIT>" ) <EOL> key_path = self . credential . credential . path . child ( b"<STR_LIT>" ) <EOL> user_credential = UserCredential . from_files ( certificate_path , key_path ) <EOL> self . assertEqual ( u"<STR_LIT>" , user_credential . username ) <EOL> def test_certificate_ou_cluster_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> cert = self . credential . credential . certificate . original <EOL> subject = cert . get_subject ( ) <EOL> self . assertEqual ( UUID ( hex = subject . OU ) , self . credential . cluster_uuid ) <EOL> class NodeCredentialTests ( <EOL> make_credential_tests ( NodeCredential , NODE_UUID , uuid = NODE_UUID ) ) : <EOL> """<STR_LIT>""" <EOL> def test_certificate_common_name_node_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> cert = self . credential . credential . certificate . original <EOL> subject = cert . get_subject ( ) <EOL> self . assertEqual ( subject . CN , b"<STR_LIT>" . format ( <EOL> uuid = self . credential . uuid ) ) <EOL> def test_certificate_ou_cluster_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> cert = self . credential . credential . certificate . original <EOL> subject = cert . get_subject ( ) <EOL> self . assertEqual ( UUID ( hex = subject . OU ) , self . credential . cluster_uuid ) <EOL> class ControlCredentialTests ( <EOL> make_credential_tests ( ControlCredential , <EOL> b"<STR_LIT>" , <EOL> hostname = b"<STR_LIT>" ) ) : <EOL> """<STR_LIT>""" <EOL> def test_certificate_subject_control_service ( self ) : <EOL> """<STR_LIT>""" <EOL> cert = self . credential . credential . certificate . original <EOL> subject = cert . get_subject ( ) <EOL> self . assertEqual ( <EOL> subject . CN , b"<STR_LIT>" ) <EOL> def test_subjectAltName_dns ( self ) : <EOL> """<STR_LIT>""" <EOL> assert_has_extension ( self , self . credential . credential , <EOL> b"<STR_LIT>" , <EOL> b"<STR_LIT>" ) <EOL> def test_subjectAltName_ipv4 ( self ) : <EOL> """<STR_LIT>""" <EOL> credential = ControlCredential . initialize ( <EOL> self . path , self . ca , begin = self . start_date , hostname = b"<STR_LIT:127.0.0.1>" ) <EOL> assert_has_extension ( self , credential . credential , <EOL> b"<STR_LIT>" , <EOL> b"<STR_LIT>" ) <EOL> class RootCredentialTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_written_keypair_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> ( True , True ) , <EOL> ( path . child ( AUTHORITY_CERTIFICATE_FILENAME ) . exists ( ) , <EOL> path . child ( AUTHORITY_KEY_FILENAME ) . exists ( ) ) <EOL> ) <EOL> def test_certificate_matches_public_key ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> ca = RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> self . assertTrue ( <EOL> ca . credential . keypair . keypair . matches ( <EOL> ca . credential . certificate . getPublicKey ( ) ) <EOL> ) <EOL> def test_certificate_matches_private_key ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> ca = RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> priv = ca . credential . keypair . keypair . original <EOL> pub = ca . credential . certificate . getPublicKey ( ) . original <EOL> pub_asn1 = crypto . dump_privatekey ( crypto . FILETYPE_ASN1 , pub ) <EOL> priv_asn1 = crypto . dump_privatekey ( crypto . FILETYPE_ASN1 , priv ) <EOL> pub_der = asn1 . DerSequence ( ) <EOL> pub_der . decode ( pub_asn1 ) <EOL> priv_der = asn1 . DerSequence ( ) <EOL> priv_der . decode ( priv_asn1 ) <EOL> pub_modulus = pub_der [ <NUM_LIT:1> ] <EOL> priv_modulus = priv_der [ <NUM_LIT:1> ] <EOL> self . assertEqual ( pub_modulus , priv_modulus ) <EOL> def test_written_keypair_reloads ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> ca1 = RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> ca2 = RootCredential . from_path ( path ) <EOL> self . assertEqual ( ca1 , ca2 ) <EOL> def test_keypair_correct_umask ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> keyPath = path . child ( AUTHORITY_KEY_FILENAME ) <EOL> st = os . stat ( keyPath . path ) <EOL> self . assertEqual ( b'<STR_LIT>' , oct ( st . st_mode & <NUM_LIT:0> <NUM_LIT> ) ) <EOL> def test_certificate_correct_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> keyPath = path . child ( AUTHORITY_CERTIFICATE_FILENAME ) <EOL> st = os . stat ( keyPath . path ) <EOL> self . assertEqual ( b'<STR_LIT>' , oct ( st . st_mode & <NUM_LIT:0> <NUM_LIT> ) ) <EOL> def test_create_error_on_non_existent_path ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> e = self . assertRaises ( <EOL> PathError , RootCredential . initialize , path , b"<STR_LIT>" <EOL> ) <EOL> expected = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( path = path . child ( <EOL> AUTHORITY_CERTIFICATE_FILENAME ) . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> def test_load_error_on_non_existent_path ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> e = self . assertRaises ( <EOL> PathError , RootCredential . from_path , path <EOL> ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( path = path . child ( AUTHORITY_CERTIFICATE_FILENAME ) . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> def test_load_error_on_non_existent_certificate_file ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> e = self . assertRaises ( <EOL> PathError , RootCredential . from_path , path <EOL> ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( path = path . child ( AUTHORITY_CERTIFICATE_FILENAME ) . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> def test_load_error_on_non_existent_key_file ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> temp_path = FilePath ( self . mktemp ( ) ) <EOL> temp_path . makedirs ( ) <EOL> ca = RootCredential . initialize ( temp_path , b"<STR_LIT>" ) <EOL> crt_path = path . child ( AUTHORITY_CERTIFICATE_FILENAME ) <EOL> crt_file = crt_path . open ( b'<STR_LIT:w>' ) <EOL> crt_file . write ( ca . credential . certificate . dumpPEM ( ) ) <EOL> crt_file . close ( ) <EOL> e = self . assertRaises ( <EOL> PathError , RootCredential . from_path , path <EOL> ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( path = path . child ( AUTHORITY_KEY_FILENAME ) . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> @ not_root <EOL> @ skip_on_broken_permissions <EOL> def test_load_error_on_unreadable_certificate_file ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> temp_path = FilePath ( self . mktemp ( ) ) <EOL> temp_path . makedirs ( ) <EOL> ca = RootCredential . initialize ( temp_path , b"<STR_LIT>" ) <EOL> crt_path = path . child ( AUTHORITY_CERTIFICATE_FILENAME ) <EOL> crt_file = crt_path . open ( b'<STR_LIT:w>' ) <EOL> crt_file . write ( ca . credential . certificate . dumpPEM ( ) ) <EOL> crt_file . close ( ) <EOL> crt_path . chmod ( <NUM_LIT> ) <EOL> key_path = path . child ( AUTHORITY_KEY_FILENAME ) <EOL> key_file = key_path . open ( b'<STR_LIT:w>' ) <EOL> key_file . write ( b"<STR_LIT>" ) <EOL> key_file . close ( ) <EOL> key_path . chmod ( <NUM_LIT> ) <EOL> e = self . assertRaises ( <EOL> PathError , RootCredential . from_path , path <EOL> ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( path = crt_path . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> @ not_root <EOL> @ skip_on_broken_permissions <EOL> def test_load_error_on_unreadable_key_file ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> temp_path = FilePath ( self . mktemp ( ) ) <EOL> temp_path . makedirs ( ) <EOL> ca = RootCredential . initialize ( temp_path , b"<STR_LIT>" ) <EOL> crt_path = path . child ( AUTHORITY_CERTIFICATE_FILENAME ) <EOL> crt_file = crt_path . open ( b'<STR_LIT:w>' ) <EOL> crt_file . write ( ca . credential . certificate . dumpPEM ( ) ) <EOL> crt_file . close ( ) <EOL> key_path = path . child ( AUTHORITY_KEY_FILENAME ) <EOL> key_file = key_path . open ( b'<STR_LIT:w>' ) <EOL> key_file . write ( b"<STR_LIT>" ) <EOL> key_file . close ( ) <EOL> key_path . chmod ( <NUM_LIT> ) <EOL> e = self . assertRaises ( <EOL> PathError , RootCredential . from_path , path <EOL> ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( path = key_path . path ) <EOL> self . assertEqual ( str ( e ) , expected ) <EOL> def test_certificate_is_self_signed ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> ca = RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> cert = ca . credential . certificate . original <EOL> issuer = cert . get_issuer ( ) . get_components ( ) <EOL> subject = cert . get_subject ( ) . get_components ( ) <EOL> self . assertEqual ( issuer , subject ) <EOL> def test_certificate_expiration ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> start_date = datetime . datetime . utcnow ( ) <EOL> expected_expiry = start_date + datetime . timedelta ( <EOL> seconds = EXPIRY_20_YEARS ) <EOL> expected_expiry = expected_expiry . strftime ( "<STR_LIT>" ) <EOL> ca = RootCredential . initialize ( path , b"<STR_LIT>" , begin = start_date ) <EOL> cert = ca . credential . certificate . original <EOL> date_str = cert . get_notAfter ( ) <EOL> self . assertEqual ( date_str , expected_expiry ) <EOL> def test_certificate_is_rsa_4096_sha_256 ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> ca = RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> cert = ca . credential . certificate . original <EOL> key = ca . credential . certificate . getPublicKey ( ) . original <EOL> self . assertEqual ( <EOL> ( crypto . TYPE_RSA , <NUM_LIT> , b'<STR_LIT>' ) , <EOL> ( key . type ( ) , key . bits ( ) , cert . get_signature_algorithm ( ) ) <EOL> ) <EOL> def test_cluster_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> ca = RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> cert = ca . credential . certificate <EOL> path2 = FilePath ( self . mktemp ( ) ) <EOL> path2 . makedirs ( ) <EOL> ca2 = RootCredential . initialize ( path2 , b"<STR_LIT>" ) <EOL> cert2 = ca2 . credential . certificate <EOL> self . assertNotEqual ( UUID ( hex = cert . getSubject ( ) . OU ) , <EOL> UUID ( hex = cert2 . getSubject ( ) . OU ) ) <EOL> def test_organizational_unit ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> RootCredential . initialize ( path , b"<STR_LIT>" ) <EOL> ca = RootCredential . from_path ( path ) <EOL> self . assertEqual ( ca . organizational_unit , <EOL> ca . credential . certificate . getSubject ( ) . OU ) <EOL> def test_overridden_cluster_id ( self ) : <EOL> """<STR_LIT>""" <EOL> path = FilePath ( self . mktemp ( ) ) <EOL> path . makedirs ( ) <EOL> cluster_id = UUID ( "<STR_LIT>" ) <EOL> RootCredential . initialize ( <EOL> path , b"<STR_LIT>" , cluster_id = cluster_id , <EOL> ) <EOL> ca = RootCredential . from_path ( path ) <EOL> self . assertEqual ( cluster_id , UUID ( ca . organizational_unit ) ) </s>
