Exemplo n.º 1
0
    def test_load_user_from_empty_request(self, admin_user):
        from dallinger.experiment_server.dashboard import load_user_from_request

        assert (
            load_user_from_request(
                self.create_request("/dashboard", "http://localhost/")
            )
            is None
        )
Exemplo n.º 2
0
    def test_load_user_with_bad_password(self, admin_user):
        from dallinger.experiment_server.dashboard import load_user_from_request

        bad_password = (codecs.encode(b"admin:password",
                                      "base64").strip().decode("ascii"))
        assert (load_user_from_request(
            self.create_request(
                "/dashboard",
                "http://localhost/",
                headers={"Authorization": "Basic {}".format(bad_password)},
            )) is None)
Exemplo n.º 3
0
    def test_load_user_from_request(self, env, admin_user):
        from dallinger.experiment_server.dashboard import load_user_from_request

        good_credentials = (codecs.encode(
            "{}:{}".format(admin_user.id, admin_user.password).encode("ascii"),
            "base64",
        ).strip().decode("ascii"))
        assert (load_user_from_request(
            self.create_request(
                "/dashboard",
                "http://localhost/",
                headers={"Authorization": "Basic {}".format(good_credentials)},
            )) is admin_user)
Exemplo n.º 4
0
    def test_load_user_with_wrong_user(self):
        from dallinger.experiment_server.dashboard import load_user_from_request
        from dallinger.experiment_server.dashboard import admin_user

        bad_credentials = (
            codecs.encode(
                "user:{}".format(admin_user.password).encode("ascii"), "base64"
            )
            .strip()
            .decode("ascii")
        )
        assert (
            load_user_from_request(
                self.create_request(
                    "/dashboard",
                    "http://localhost/",
                    headers={"Authorization": "Basic {}".format(bad_credentials)},
                )
            )
            is None
        )