def test_created(self): args = mock_tools.make_args({"vpc_key": None}) httpretty.register_uri( httpretty.GET, "{api_endpoint}/saturn/v1/{account_id}/installations?vpc_key=:vpc_key" .format(**vars(args)), status=200, body='[' '{' '"account_id":"010000001",' '"deployment_id":"582C62B4-9D1D-4F1C-9117-BE4198198861",' '"vpc_key":"/aws/us-west-1/vpc/vpc-123456"' '}' ']', content_type="text/json") context = mock_tools.make_context(args) result = alertlogiccli.commands.deployment.installation.InstallationStatus( ).execute(context) assert (result == '[' '{' '"account_id":"010000001",' '"deployment_id":"582C62B4-9D1D-4F1C-9117-BE4198198861",' '"vpc_key":"/aws/us-west-1/vpc/vpc-123456"' '}' ']')
def test_created(self): args = mock_tools.make_args({"vpc_key": None}) httpretty.register_uri( httpretty.GET, "{api_endpoint}/skaletor/v1/{account_id}/scanners?deployment_id=:deployment_id&vpc_key=:vpc_key" .format(**vars(args)), status=200, body='{' '"count":1,' '"scanners":[' '{' '"account_id":"010000001",' '"deployment_id":"582C62B4-9D1D-4F1C-9117-BE4198198861",' '"vpc_key":"/aws/us-west-1/vpc/vpc-123456",' '"scaling_policy":"small",' '"num_scanners_required":1' '}' ']' '}', content_type="text/json") context = mock_tools.make_context(args) result = alertlogiccli.commands.deployment.scanner.ScannerEstimation( ).execute(context) assert (result == '{' '"count":1,' '"scanners":[' '{' '"account_id":"010000001",' '"deployment_id":"582C62B4-9D1D-4F1C-9117-BE4198198861",' '"num_scanners_required":1,' '"scaling_policy":"small",' '"vpc_key":"/aws/us-west-1/vpc/vpc-123456"' '}' ']' '}')
def test_created(self): args = mock_tools.make_args({ "provider_id": "123456789012", "provider_type": "aws", "vpc_id": "vpc-1", "subnet_id": "subnet-1" }) httpretty.register_uri( httpretty.POST, "{api_endpoint}/otis/v2/{account_id}/options".format(**vars(args)), status=201, body='{' '"id": "1", ' '"name": "predefined_security_subnet", ' '"scope":{"provider_type": "aws", "provider_id":"123456789012", "vpc_id": "vpc-1"}, ' '"value": "subnet-1"' '}', content_type="text/json") context = mock_tools.make_context(args) result = alertlogiccli.commands.deployment.subnet.SetSubnet().execute( context) assert ( result == '{' '"id":"1",' '"name":"predefined_security_subnet",' '"scope":{"provider_id":"123456789012","provider_type":"aws","vpc_id":"vpc-1"},' '"value":"subnet-1"' '}')
def test_server_error(self): args = mock_tools.make_args() httpretty.register_uri( httpretty.GET, "{api_endpoint}/otis/v2/{account_id}/options".format(**vars(args)), status=500) with pytest.raises(alertlogiccli.command.InvalidHTTPResponse): context = mock_tools.make_context(args) alertlogiccli.commands.deployment.subnet.GetConfiguration( ).execute(context)
def test_ok(self): args = mock_tools.make_args({"asset_key": "HOST_KEY"}) body = json.dumps(LIST_REPLY_JSON) httpretty.register_uri(httpretty.PUT, "{api_endpoint}/scheduler/v1/{account_id}/{deployment_id}/scan?asset={}".format(**vars(args)), status=200, content_type="text/json") context = mock_tools.make_context(args) result = alertlogiccli.commands.deployment.scan_queue.ListScanQueues().execute(context) assert(result == "ok")
def test_server_error(self): args = mock_tools.make_args() httpretty.register_uri( httpretty.GET, "{api_endpoint}/sources/v1/{account_id}/sources/{deployment_id}". format(**vars(args)), status=500) with pytest.raises(alertlogiccli.command.InvalidHTTPResponse): context = mock_tools.make_context(args) alertlogiccli.commands.deployment.mode.GetMode().execute(context)
def test_server_error(self): args = mock_tools.make_args({"deployment_id": "2", "vpc_key": None}) httpretty.register_uri( httpretty.POST, "{api_endpoint}/saturn/v1/{account_id}/redeploy?deployment_id=:deployment_id&vpc_key=:vpc_key" .format(**vars(args)), status=500) with pytest.raises(alertlogiccli.command.InvalidHTTPResponse): context = mock_tools.make_context(args) alertlogiccli.commands.deployment.installation.Redeploy().execute( context)
def test_not_found(self): args = mock_tools.make_args({"vpc_key": None}) httpretty.register_uri( httpretty.GET, "{api_endpoint}/saturn/v1/{account_id}/installations?vpc_key=:vpc_key" .format(**vars(args)), status=404) with pytest.raises(alertlogiccli.command.InvalidHTTPResponse): context = mock_tools.make_context(args) alertlogiccli.commands.deployment.installation.InstallationStatus( ).execute(context)
def test_server_error(self): args = mock_tools.make_args({"vpc_key": None}) httpretty.register_uri( httpretty.GET, "{api_endpoint}/skaletor/v1/{account_id}/scanners?deployment_id=:deployment_id&vpc_key=:vpc_key" .format(**vars(args)), status=500) with pytest.raises(alertlogiccli.command.InvalidHTTPResponse): context = mock_tools.make_context(args) alertlogiccli.commands.deployment.scanner.ScannerEstimation( ).execute(context)
def test_created(self): args = mock_tools.make_args({"deployment_id": "2", "vpc_key": None}) httpretty.register_uri( httpretty.POST, "{api_endpoint}/saturn/v1/{account_id}/redeploy?deployment_id=:deployment_id&vpc_key=:vpc_key" .format(**vars(args)), status=204, ) context = mock_tools.make_context(args) result = alertlogiccli.commands.deployment.installation.Redeploy( ).execute(context) assert (result == "ok")
def test_invalid_response(self): args = mock_tools.make_args() httpretty.register_uri( httpretty.GET, "{api_endpoint}/sources/v1/{account_id}/sources/{deployment_id}". format(**vars(args)), body='INVALID_BODY', status=200, content_type="text/json") with pytest.raises(alertlogiccli.command.InvalidServiceResponse): context = mock_tools.make_context(args) alertlogiccli.commands.deployment.mode.GetMode().execute(context)
def test_ok(self): args = mock_tools.make_args() httpretty.register_uri( httpretty.GET, "{api_endpoint}/sources/v1/{account_id}/sources/{deployment_id}". format(**vars(args)), body='{"source": {"type": "environment", "config": {"deployment_mode": "readonly"}}}', status=200, content_type="text/json" ) context = mock_tools.make_context(args) result = alertlogiccli.commands.deployment.mode.GetMode().execute(context) assert (result == "readonly")
def test_server_error(self): args = mock_tools.make_args({ "provider_id": "123456789012", "provider_type": "aws", "vpc_id": "vpc-1", "subnet_id": "subnet-1" }) httpretty.register_uri( httpretty.POST, "{api_endpoint}/otis/v2/{account_id}/options".format(**vars(args)), status=500) with pytest.raises(alertlogiccli.command.InvalidHTTPResponse): context = mock_tools.make_context(args) alertlogiccli.commands.deployment.subnet.SetSubnet().execute( context)
def test_ok(self): args = mock_tools.make_args() body = json.dumps(LIST_REPLY_JSON) httpretty.register_uri(httpretty.GET, "{api_endpoint}/scheduler/v1/{account_id}/{deployment_id}/list".format(**vars(args)), body=body, status=200, content_type="text/json") context = mock_tools.make_context(args) result = alertlogiccli.commands.deployment.scan_queue.ListScanQueues().execute(context) expected_sorted = json.dumps(LIST_EXPECTED_JSON, sort_keys=True) result_sorted = json.dumps(json.loads(result), sort_keys=True) assert(expected_sorted == result_sorted)
def test_ok(self): args = mock_tools.make_args() body = json.dumps(GET_STATUS_REPLY_JSON) httpretty.register_uri(httpretty.GET, "{api_endpoint}/launcher/v1/{account_id}/environments/{deployment_id}".format(**vars(args)), body=body, status=200, content_type="text/json") context = mock_tools.make_context(args) result = alertlogiccli.commands.deployment.status.GetStatus().execute(context) expected_sorted = json.dumps(json.loads(body), sort_keys=True) result_sorted = json.dumps(json.loads(result), sort_keys=True) assert(expected_sorted == result_sorted)
def test_server_fail(self): args = mock_tools.make_args(additional_args={"mode": "readonly"}) httpretty.register_uri( httpretty.GET, "{api_endpoint}/sources/v1/{account_id}/sources/{deployment_id}". format(**vars(args)), body='{"source": {"type": "environment"}}', status=200, content_type="text/json") httpretty.register_uri( httpretty.POST, "{api_endpoint}/sources/v1/{account_id}/sources/{deployment_id}". format(**vars(args)), status=500) with pytest.raises(alertlogiccli.command.InvalidHTTPResponse): context = mock_tools.make_context(args) alertlogiccli.commands.deployment.mode.SetMode().execute(context)