def test_ok(self, logged_in_single_user): # Create a device authset = crypto.rand_id_data() keypair = crypto.get_keypair_rsa() dapi = api.DevicesDevauth() r = dapi.post_auth_request(authset, keypair[1], keypair[0]) assert r.status_code == 401 # Device should be listed as pending c = cli.MenderCliCoverage() r = c.run( "--server", "https://mender-api-gateway", "--skip-verify", "devices", "list" ) assert r.returncode == 0, r.stderr expect_output(r.stdout, "Status: pending") # Get and accept the device token = Path(DEFAULT_TOKEN_PATH).read_text() mapi = api.ManagementDevauth(token) r = mapi.get_devices() assert r.status_code == 200 devices = r.json() device_id = devices[0]["id"] authset_id = devices[0]["auth_sets"][0]["id"] r = mapi.set_device_auth_status(device_id, authset_id, "accepted") assert r.status_code == 204 # Device should now be listed as accepted c = cli.MenderCliCoverage() r = c.run( "--server", "https://mender-api-gateway", "--skip-verify", "devices", "list" ) assert r.returncode == 0, r.stderr expect_output(r.stdout, "Status: accepted")
def test_ok(self, logged_in_single_user, valid_artifact): c = cli.Cli() r = c.run('--server', 'https://mender-api-gateway', \ '--skip-verify', \ 'artifacts', 'upload', \ '--description', 'foo', valid_artifact) assert r.returncode == 0, r.stderr expect_output(r.stdout, 'upload successful') token = Path(DEFAULT_TOKEN_PATH).read_text() dapi = api.Deployments(token) r = dapi.get_artifacts() assert r.status_code == 200 artifacts = r.json() assert len(artifacts) == 1 artifact = artifacts[0] assert artifact['name'] == 'artifact-foo' assert artifact['description'] == 'foo' assert artifact['device_types_compatible'] == ['device-foo']
def test_error_no_server(self, valid_artifact, clean_deployments_db): c = cli.Cli() r = c.run('--skip-verify', \ 'artifacts', 'upload', \ '--description', 'foo', valid_artifact) assert r.returncode!=0 expect_output(r.stderr, '"server" not set')
def test_error_no_login(self, valid_artifact): c = cli.Cli() r = c.run('--server', 'https://mender-api-gateway', \ '--skip-verify', \ 'artifacts', 'upload', \ '--description', 'foo', valid_artifact) assert r.returncode != 0 expect_output(r.stderr, 'FAILURE', 'Please Login first')
def test_error_no_server(self, single_user): c = cli.Cli() r = c.run('login', \ '--skip-verify', \ '--username', '*****@*****.**', \ '--password', 'youcantguess') assert r.returncode != 0 expect_output(r.stderr, '"server" not set')
def test_error_wrong_creds(self, single_user): c = cli.Cli() r = c.run('login', \ '--server', 'https://mender-api-gateway', \ '--skip-verify', \ '--username', '*****@*****.**', \ '--password', 'youcantguess') assert r.returncode != 0 expect_output(r.stderr, 'FAILURE: login failed with status 401')
def test_login_from_configuration_file(self, single_user): """test that the configuration file parameters are respected""" # Wrong username and password conf = """ { "username": "******", "password": "******", "server": "https://mender-api-gateway" } """ self._write_mender_cli_conf(conf) c = cli.Cli() r = c.run("login", "--skip-verify") assert r.returncode != 0, r.stderr expect_output(r.stderr, "FAILURE: login failed with status 401") # correct username and password, wrong server conf = """ { "username": "******", "password": "******", "server": "https://wrong.server.com" } """ self._write_mender_cli_conf(conf) r = c.run("login", "--skip-verify") assert r.returncode != 0, r.stderr expect_output(r.stderr, "FAILURE:", "request failed") # correct username, password and server conf = """ { "username": "******", "password": "******", "server": "https://mender-api-gateway" } """ self._write_mender_cli_conf(conf) r = c.run("login", "--skip-verify") assert r.returncode == 0, r.stderr
def test_ok(self, single_user, cleanup_token): c = cli.Cli() r = c.run('login', \ '--server', 'https://mender-api-gateway', \ '--skip-verify', \ '--username', '*****@*****.**', \ '--password', 'youcantguess') assert r.returncode == 0, r.stderr self.__check_token_at(DEFAULT_TOKEN_PATH) expect_output(r.stdout, \ 'login successful')
def test_error_wrong_creds(self, single_user): c = cli.Cli() r = c.run( "login", "--server", "https://mender-api-gateway", "--skip-verify", "--username", "*****@*****.**", "--password", "youcantguess", ) assert r.returncode != 0 expect_output(r.stderr, "FAILURE: login failed with status 401")
def test_ok_custom_path(self, single_user, cleanup_token): c = cli.Cli() custom_path = '/tests/authtoken' r = c.run('login', \ '--server', 'https://mender-api-gateway', \ '--skip-verify', \ '--token', '/tests/authtoken', \ '--username', '*****@*****.**', \ '--password', 'youcantguess') assert r.returncode == 0, r.stderr self.__check_token_at(custom_path) expect_output(r.stdout, \ 'login successful')
def test_ok(self, single_user, cleanup_token): c = cli.Cli() r = c.run( "login", "--server", "https://mender-api-gateway", "--skip-verify", "--username", "*****@*****.**", "--password", "youcantguess", ) assert r.returncode == 0, r.stderr self.__check_token_at(DEFAULT_TOKEN_PATH) expect_output(r.stdout, "login successful")
def test_ok_custom_path(self, single_user, cleanup_token): c = cli.Cli() custom_path = "/tests/authtoken" r = c.run( "login", "--server", "https://mender-api-gateway", "--skip-verify", "--token", "/tests/authtoken", "--username", "*****@*****.**", "--password", "youcantguess", ) assert r.returncode == 0, r.stderr self.__check_token_at(custom_path) expect_output(r.stdout, "login successful")