<s> import os <EOL> import tempfile <EOL> import subprocess <EOL> import pytest <EOL> from koi . keygen import ( <EOL> argument_parser , check_cert , check_key_cert_match , gen_non_ca_cert , main , <EOL> DEFAULT_CERTS_DIR ) <EOL> @ pytest . mark . parametrize ( "<STR_LIT>" , [ <EOL> ( '<STR_LIT>' , False , '<STR_LIT:localhost>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT:localhost>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> def test_argument_parser ( args , is_ca , filename , dirname ) : <EOL> parser = argument_parser ( ) <EOL> args = parser . parse_args ( args . split ( ) ) <EOL> assert args . is_ca == is_ca <EOL> assert args . filename == filename <EOL> assert os . path . basename ( args . dirname ) == dirname <EOL> def test_check_cert_localhost ( ) : <EOL> out = check_cert ( os . path . join ( DEFAULT_CERTS_DIR , '<STR_LIT>' ) ) <EOL> assert '<STR_LIT:localhost>' in out <EOL> def test_check_cert_ip ( ) : <EOL> out = check_cert ( os . path . join ( DEFAULT_CERTS_DIR , '<STR_LIT>' ) ) <EOL> assert '<STR_LIT:127.0.0.1>' in out <EOL> def test_key_cert_match ( ) : <EOL> key = os . path . join ( DEFAULT_CERTS_DIR , '<STR_LIT>' ) <EOL> crt = os . path . join ( DEFAULT_CERTS_DIR , '<STR_LIT>' ) <EOL> assert check_key_cert_match ( key , crt ) <EOL> def test_gen_ca_cert ( ) : <EOL> tmp_dir = tempfile . mkdtemp ( ) <EOL> main ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , tmp_dir ] ) <EOL> key = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> crt = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> assert check_key_cert_match ( key , crt ) <EOL> def test_gen_non_ca_cert ( ) : <EOL> tmp_dir = tempfile . mkdtemp ( ) <EOL> main ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , tmp_dir ] ) <EOL> ca_key = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> ca_crt = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> assert check_key_cert_match ( ca_key , ca_crt ) <EOL> gen_non_ca_cert ( '<STR_LIT>' , tmp_dir , <NUM_LIT> , [ '<STR_LIT:127.0.0.1>' ] , [ ] , ca_crt , ca_key ) <EOL> key = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> crt = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> assert check_key_cert_match ( key , crt ) <EOL> def test_gen_non_ca_cert_shell ( ) : <EOL> tmp_dir = tempfile . mkdtemp ( ) <EOL> key = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> crt = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> main ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , tmp_dir ] ) <EOL> assert check_key_cert_match ( key , crt ) <EOL> def test_run_module_as_script ( ) : <EOL> tmp_dir = tempfile . mkdtemp ( ) <EOL> key = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> crt = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> subprocess . call ( <EOL> '<STR_LIT>' . format ( tmp_dir ) , <EOL> shell = True ) <EOL> assert check_key_cert_match ( key , crt ) </s>
