def test_all_parameters_are_correct(self, server_url):
     request = authorize.request(
         server_url,
         "this is a tenant tolken",
         {"this is identity": "data"},
         key.generate_key(),
         "this is the server certificate",
     )
     assert request == "jwttoken"
 def test_no_key(self, caplog, server_url):
     request = authorize.request(
         server_url,
         "this is a tenant token",
         {"this is identity": "data"},
         None,
         "this is the server certificate",
     )
     assert request is None
     assert "No private key provided, unable to authorize" in caplog.text
 def test_no_identity_data(self, caplog, server_url):
     request = authorize.request(
         server_url,
         "this is a tenant token",
         {},
         key.generate_key(),
         "this is the server certificate",
     )
     assert request is None
     assert "Identity data not provided, unable to authorize" in caplog.text
 def test_server_url(self, caplog, test_input, expected):
     request = authorize.request(
         test_input,
         "this is a tenant token",
         {"this is identity": "data"},
         key.generate_key(),
         "this is the server certificate",
     )
     assert expected in caplog.text
     assert request is None
Exemple #5
0
 def run(self, context):
     log.info("Authorizing...")
     log.debug(f"Current context: {context}")
     time.sleep(3)
     return authorize.request(
         context.config.ServerURL,
         context.config.TenantToken,
         context.identity_data,
         context.private_key,
         context.config.ServerCertificate,
     )
def report(args):
    context = statemachine.Context()
    context = statemachine.Init().run(context)
    jwt = authorize.request(
        context.config.ServerURL,
        context.config.TenantToken,
        context.identity_data,
        context.private_key,
        context.config.ServerCertificate,
    )
    if not jwt:
        log.error("Failed to authorize with the Mender server")
        sys.exit(1)
    try:
        with open(settings.PATHS.lockfile_path) as f:
            deployment_id = f.read()
            if not deployment_id:
                log.error("No deployment ID found in the lockfile")
                sys.exit(1)
    except FileNotFoundError:
        log.error("No update in progress...")
        sys.exit(1)
    if args.success:
        log.info("Reporting a successful update to the Mender server")
        if not deployments.report(
                context.config.ServerURL,
                deployments.STATUS_SUCCESS,
                deployment_id,
                context.config.ServerCertificate,
                jwt,
                deployment_logger=None,
        ):
            log.error(
                "Failed to report the successful update status to the Mender server"
            )
            sys.exit(1)
    elif args.failure:
        log.info("Reporting a failed update to the Mender server")
        log.parent.deployment_log_handler.enable()
        if not deployments.report(
                context.config.ServerURL,
                deployments.STATUS_FAILURE,
                deployment_id,
                context.config.ServerCertificate,
                jwt,
                log.parent.deployment_log_handler,
        ):
            log.error(
                "Failed to report the failed update status to the Mender server"
            )
            sys.exit(1)
    else:
        log.error("No report status given")
        sys.exit(1)
Exemple #7
0
    def run(self, context):
        if not context.retry_timer.is_it_time():
            return None

        log.info("Authorizing...")
        log.debug(f"Current context: {context}")
        return authorize.request(
            context.config.ServerURL,
            context.config.TenantToken,
            context.identity_data,
            context.private_key,
            context.config.ServerCertificate,
        )
    def test_staus_codes(self, httpserver, caplog, server_url):
        caplog.set_level(log.ERROR)
        httpserver.expect_request(
            "/api/devices/v1/authentication/auth_requests",
            method="post").respond_with_json({"jwt": "token"}, status=201)

        request = authorize.request(
            server_url,
            "this is a tenant tolken",
            {"this is identity": "data"},
            key.generate_key(),
            "this is the server certificate",
        )
        assert "The client failed to authorize with the Mender server." in caplog.text
        assert request is None
def report_no_install_script(context):

    jwt = authorize.request(
        context.config.ServerURL,
        context.config.TenantToken,
        context.identity_data,
        context.private_key,
        context.config.ServerCertificate,
    )

    return deployments.report(
            context.config.ServerURL,
            "failure",
            context.deployment_id,
            context.config.ServerCertificate,
            jwt
    )