<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import os <EOL> import pwd <EOL> import grp <EOL> import random <EOL> from salttesting import skipIf <EOL> from salttesting . helpers import ( <EOL> ensure_in_syspath , <EOL> destructiveTest ) <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> import salt . utils <EOL> from salt . utils . pycrypto import gen_hash <EOL> import integration <EOL> from salt . ext . six . moves import range <EOL> def gen_password ( ) : <EOL> '''<STR_LIT>''' <EOL> alphabet = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> password = '<STR_LIT>' <EOL> for _ in range ( <NUM_LIT:20> ) : <EOL> next_index = random . randrange ( len ( alphabet ) ) <EOL> password += alphabet [ next_index ] <EOL> hashed_pwd = gen_hash ( '<STR_LIT>' , password , '<STR_LIT>' ) <EOL> return ( password , hashed_pwd ) <EOL> class AuthTest ( integration . ShellCase ) : <EOL> '''<STR_LIT>''' <EOL> _call_binary_ = '<STR_LIT>' <EOL> is_not_root = os . geteuid ( ) != <NUM_LIT:0> <EOL> userA = '<STR_LIT>' <EOL> userB = '<STR_LIT>' <EOL> group = '<STR_LIT>' <EOL> @ destructiveTest <EOL> @ skipIf ( is_not_root , '<STR_LIT>' ) <EOL> def setUp ( self ) : <EOL> for user in ( self . userA , self . userB ) : <EOL> try : <EOL> pwd . getpwnam ( user ) <EOL> except KeyError : <EOL> self . run_call ( '<STR_LIT>' . format ( user ) ) <EOL> try : <EOL> grp . getgrnam ( self . group ) <EOL> except KeyError : <EOL> self . run_call ( '<STR_LIT>' . format ( self . group ) ) <EOL> self . run_call ( '<STR_LIT>' . format ( self . userB , self . group ) ) <EOL> def test_pam_auth_valid_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> password , hashed_pwd = gen_password ( ) <EOL> set_pw_cmd = "<STR_LIT>" . format ( <EOL> self . userA , <EOL> password if salt . utils . is_darwin ( ) else hashed_pwd <EOL> ) <EOL> self . run_call ( set_pw_cmd ) <EOL> cmd = ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . userA , password ) ) <EOL> resp = self . run_salt ( cmd ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in resp <EOL> ) <EOL> def test_pam_auth_invalid_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> cmd = ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( '<STR_LIT>' ) ) <EOL> resp = self . run_salt ( cmd ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in '<STR_LIT>' . join ( resp ) <EOL> ) <EOL> def test_pam_auth_valid_group ( self ) : <EOL> '''<STR_LIT>''' <EOL> password , hashed_pwd = gen_password ( ) <EOL> set_pw_cmd = "<STR_LIT>" . format ( <EOL> self . userB , <EOL> password if salt . utils . is_darwin ( ) else hashed_pwd <EOL> ) <EOL> self . run_call ( set_pw_cmd ) <EOL> cmd = ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . userB , password ) ) <EOL> resp = self . run_salt ( cmd ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in resp <EOL> ) <EOL> @ destructiveTest <EOL> @ skipIf ( is_not_root , '<STR_LIT>' ) <EOL> def test_zzzz_tearDown ( self ) : <EOL> for user in ( self . userA , self . userB ) : <EOL> if pwd . getpwnam ( user ) : <EOL> self . run_call ( '<STR_LIT>' . format ( user ) ) <EOL> if grp . getgrnam ( self . group ) : <EOL> self . run_call ( '<STR_LIT>' . format ( self . group ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( AuthTest ) </s>
