def test_loginTwoConsumersLoginNoGroupsPresent(self, mockKongGet, mockLdapSimpleBind): appObj.init(envWithNoGroups, testingMode = True) self.testClient = appObj.flaskAppObject.test_client() self.testClient.testing = True username = '******' password = '******' result = self.testClient.get('/login/',headers={'Authorization': _basic_auth_str('Basic ', username, password)}) self.assertEqual(result.status_code, 200, msg="Login returned wrong value - " + result.get_data(as_text=True)) resultJSON = json.loads(result.get_data(as_text=True)) #print(resultJSON['JWTToken']) #print(resultJSON['TokenExpiry']) self.assertNotEqual(resultJSON['JWTToken'],'') decoded = jwt.decode(resultJSON['JWTToken'], b64decode("some_secretxx"), algorithms=['HS256']) self.assertEqual(decoded['iss'],"some_key") self.assertEqual(decoded['groups'],[]) self.assertEqual(decoded['username'],username) #Now log in as a second user username2 = 'TestUser002' password2 = 'TestPassword' result = self.testClient.get('/login/',headers={'Authorization': _basic_auth_str('Basic ', username2, password2)}) self.assertEqual(result.status_code, 200) get_expected_calls = [ call('http://kong:8001/consumers/ldap_TestUser001'), call('http://kong:8001/consumers/ldap_TestUser001/acls'), call('http://kong:8001/consumers/ldap_TestUser001/jwt/ldap_TestUser001_kong_ldap_login_endpoint_jwtkey'), call('http://kong:8001/consumers/ldap_TestUser002'), call('http://kong:8001/consumers/ldap_TestUser002/acls'), call('http://kong:8001/consumers/ldap_TestUser002/jwt/ldap_TestUser002_kong_ldap_login_endpoint_jwtkey') ] mockKongGet.assert_has_calls(get_expected_calls)
def setUp(self): self.pre_setUpHook() appObj.init(self._getEnvironment(), self.standardStartupTime, testingMode=True) self.testClient = appObj.flaskAppObject.test_client() self.testClient.testing = True
def test_loginGoodConsumerNoGroupsPresent(self, mockLdapSimpleBind, mockKongGet): appObj.init(envWithNoGroups, testingMode=True) self.testClient = appObj.flaskAppObject.test_client() self.testClient.testing = True username = '******' password = '******' result = self.testClient.get('/login/', headers={ 'Authorization': _basic_auth_str( 'Basic ', username, password) }) self.assertEqual(result.status_code, 200) resultJSON = json.loads(result.get_data(as_text=True)) #print(resultJSON['JWTToken']) #print(resultJSON['TokenExpiry']) self.assertNotEqual(resultJSON['JWTToken'], '') decoded = jwt.decode(resultJSON['JWTToken'], b64decode("some_secretxx"), algorithms=['HS256']) self.assertEqual(decoded['iss'], "some_key") self.assertEqual(decoded['groups'], []) self.assertEqual(decoded['username'], username)
def test_refreshSessionTimeoutLessThanRefeshTokenTimoutGeneratesInvalidConfigException( self): envForTest = copy.deepcopy(env) envForTest['APIAPP_REFRESH_TOKEN_TIMEOUT'] = '130' envForTest['APIAPP_REFRESH_SESSION_TIMEOUT'] = '115' with self.assertRaises(Exception) as context: appObj.init(envForTest, self.standardStartupTime, testingMode=True) self.checkGotRightException(context, invalidConfigurationException)
def setUp(self): # curDatetime = datetime.datetime.now(pytz.utc) # for testing always pretend the server started at a set datetime self.pre_setUpHook() appObj.init(self._getEnvironment(), self.standardStartupTime, testingMode=True) self.testClient = appObj.flaskAppObject.test_client() self.testClient.testing = True
def setUp(self): # curDatetime = datetime.datetime.now(pytz.utc) # for testing always pretend the server started at a set datetime appObj.init( env, self.standardStartupTime, testingMode=True, objectStoreTestingPopulationHookFn=self.objectStorePopulationHook) self.testClient = appObj.flaskAppObject.test_client() self.testClient.testing = True
def test_missingUserForJobs(self): env = { 'APIAPP_MODE': 'DOCKER', 'APIAPP_VERSION': 'TEST-3.3.3', 'APIAPP_FRONTEND': '../app', 'APIAPP_APIURL': 'http://apiurlxxx:45/aa/bb/cc', 'APIAPP_APIACCESSSECURITY': '[]', 'APIAPP_USERFORJOBS': 'root', } with self.assertRaises(Exception) as context: appObj.init(env, self.standardStartupTime) self.checkGotRightException(context, MissingGroupForJobsException)
def test_TrueSkipUserCheck(self): env = { 'APIAPP_MODE': 'DOCKER', 'APIAPP_VERSION': 'TEST-3.3.3', 'APIAPP_FRONTEND': '../app', 'APIAPP_APIURL': 'http://apiurlxxx:45/aa/bb/cc', 'APIAPP_APIACCESSSECURITY': '[]', 'APIAPP_USERFORJOBS': 'root', 'APIAPP_GROUPFORJOBS': 'root', 'APIAPP_SKIPUSERCHECK': 'True' } with self.assertRaises(Exception) as context: appObj.init(env, self.standardStartupTime) self.checkGotRightException( context, getInvalidEnvVarParamaterException('APIAPP_SKIPUSERCHECK'))
def test_ExecuteAsDockJobUserUser(self): env = { 'APIAPP_MODE': 'DOCKER', 'APIAPP_VERSION': 'TEST-3.3.3', 'APIAPP_FRONTEND': '../app', 'APIAPP_APIURL': 'http://apiurlxxx:45/aa/bb/cc', 'APIAPP_APIACCESSSECURITY': '[]', 'APIAPP_USERFORJOBS': 'dockjobuser', 'APIAPP_GROUPFORJOBS': 'dockjobgroup', } appObj.init(env, self.standardStartupTime) testClient = appObj.flaskAppObject.test_client() testClient.testing = True cmdToExecute = 'whoami' expResSTDOUT = 'dockjobuser\n' res = appObj.jobExecutor.executeCommand(cmdToExecute) self.assertEqual(res.stdout.decode(), expResSTDOUT) appObj.jobExecutor.stopThreadRunning() testClient = None
from appObj import appObj import os import sys appObj.init(os.environ) expectedNumberOfParams = 0 if ((len(sys.argv) - 1) != expectedNumberOfParams): raise Exception('Wrong number of paramaters passed (Got ' + str((len(sys.argv) - 1)) + " expected " + str(expectedNumberOfParams) + ")") appObj.run()
from appObj import appObj import sys import os import datetime import pytz curDatetime = datetime.datetime.now(pytz.utc) appObj.init(os.environ, curDatetime) def call_exit_gracefully(): appObj.exit_gracefully(None, None) try: import uwsgi uwsgi.atexit = call_exit_gracefully except: print('uwsgi not availiable') globalFlaskAppObj = appObj.flaskAppObject if __name__ == "__main__": #Custom handler to allow me to use my own logger from werkzeug.serving import WSGIRequestHandler, _log class CustomRequestHandler(WSGIRequestHandler): # Stop logging sucessful health checks #Stops flask logging health checks # dosen't work in container with nginx
from appObj import appObj print('Start of test program') appObj.init() appObj.run() #unicorn.set_layout(unicorn.AUTO) #unicorn.rotation(0) #unicorn.brightness(0.5) #width,height=unicorn.get_shape() #for x in range(0,width): # for y in range(0,height): # print("(" + str(x) + "," + str(y) + ")") # unicorn.set_pixel(x, y, 255, 255, 255) #unicorn.show() print('End of test program')