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.MenderCliCoverage() 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_configuration_parameter_override(self, single_user): """test that parameters listed in the configuration file can be overridden on the CLI All parameters in the configuration are wrong, and should therefore be overridden by the CLI parameters """ conf = """ { "username": "******", "password": "******", "server": "https://wrong.server.com" } """ self._write_mender_cli_conf(conf) c = cli.MenderCliCoverage() r = c.run( "login", "--server", "https://mender-api-gateway", "--skip-verify", "--username", "*****@*****.**", "--password", "youcantguess", ) assert r.returncode == 0, r.stderr
def test_error_no_login(self, valid_artifact): c = cli.MenderCliCoverage() 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_download(self, device_id=running_device_id): c = cli.MenderCliCoverage() r = c.run( "--server", "https://mender-api-gateway", "--skip-verify", "cp", device_id + ":" + "/etc/mender/mender.conf", "./mender.conf", ) assert r.returncode == 0, r.stderr assert r.stdout
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.MenderCliCoverage() 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_upload(self, device_id=running_device_id): # Create a dummy file to upload with open("./mender.conf.new") as f: f.write("foobarbaz") c = cli.MenderCliCoverage() r = c.run( "--server", "https://mender-api-gateway", "--skip-verify", "cp", "./mender.conf.new", device_id + ":" + "/etc/mender/mender.conf", ) assert r.returncode == 0, r.stderr
def test_error_wrong_creds(self, single_user): c = cli.MenderCliCoverage() 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_stdin(self, single_user): """test login reading password from stdin""" conf = """ { "username": "******", "server": "https://mender-api-gateway" } """ self._write_mender_cli_conf(conf) c = cli.MenderCliCoverage() r = c.run_and_enter_password("login", "--skip-verify", password="******") assert r.returncode == 0, r.stderr
def test_ok(self, single_user, cleanup_token): c = cli.MenderCliCoverage() 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.MenderCliCoverage() 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")