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")
Exemple #2
0
    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']
Exemple #3
0
    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')
Exemple #4
0
    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')
Exemple #5
0
    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')
Exemple #6
0
    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')
Exemple #7
0
    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
Exemple #8
0
    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')
Exemple #9
0
    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")
Exemple #10
0
    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')
Exemple #11
0
    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")
Exemple #12
0
    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")