コード例 #1
0
ファイル: test_user_model.py プロジェクト: heynemann/wight
    def test_authenticating_with_wrong_pass_returns_none(self):
        created_user = UserFactory.create()

        exists, user = User.authenticate(email="*****@*****.**", password="******")
        expect(exists).to_be_false()
        expect(user).to_be_null()

        exists, user = User.authenticate(email=created_user.email, password="******")
        expect(exists).to_be_true()
        expect(user).to_be_null()
コード例 #2
0
ファイル: test_user_model.py プロジェクト: movermeyer/wight
    def test_authenticating_with_wrong_pass_returns_none(self):
        created_user = UserFactory.create()

        exists, user = User.authenticate(email="*****@*****.**",
                                         password="******")
        expect(exists).to_be_false()
        expect(user).to_be_null()

        exists, user = User.authenticate(email=created_user.email,
                                         password="******")
        expect(exists).to_be_true()
        expect(user).to_be_null()
コード例 #3
0
ファイル: authentication.py プロジェクト: movermeyer/wight
    def get(self):
        email = self.request.headers.get("Email", None)
        password = self.request.headers.get("Password", None)

        if not email or not password:
            self.set_status(400)
            self.finish()
            return

        exists, user = User.authenticate(
            email,
            password,
            expiration=self.application.config.TOKEN_EXPIRATION_IN_MINUTES)

        if not exists:
            self.set_status(404)
            self.finish()
            return

        if user is None:
            self.set_status(403)
            self.finish()
            return

        self.set_status(200)
        self.set_header("Token", user.token)
        self.set_header("Token-Expiration", user.token_expiration.isoformat())
        self.write("OK")
        self.finish()
コード例 #4
0
ファイル: authentication.py プロジェクト: heynemann/wight
    def get(self):
        email = self.request.headers.get("Email", None)
        password = self.request.headers.get("Password", None)

        if not email or not password:
            self.set_status(400)
            self.finish()
            return

        exists, user = User.authenticate(email, password, expiration=self.application.config.TOKEN_EXPIRATION_IN_MINUTES)

        if not exists:
            self.set_status(404)
            self.finish()
            return

        if user is None:
            self.set_status(403)
            self.finish()
            return

        self.set_status(200)
        self.set_header("Token", user.token)
        self.set_header("Token-Expiration", user.token_expiration.isoformat())
        self.write("OK")
        self.finish()
コード例 #5
0
ファイル: test_user_model.py プロジェクト: heynemann/wight
    def test_authenticate_using_token(self):
        user = UserFactory.create()

        exists, auth_user = User.authenticate(email=user.email, password=UserFactory.get_default_password())
        expect(auth_user).not_to_be_null()

        auth_user = User.authenticate_with_token(token=auth_user.token)
        expect(auth_user).not_to_be_null()
コード例 #6
0
ファイル: test_user_model.py プロジェクト: movermeyer/wight
    def test_authenticate_using_token(self):
        user = UserFactory.create()

        exists, auth_user = User.authenticate(
            email=user.email, password=UserFactory.get_default_password())
        expect(auth_user).not_to_be_null()

        auth_user = User.authenticate_with_token(token=auth_user.token)
        expect(auth_user).not_to_be_null()
コード例 #7
0
ファイル: test_user_model.py プロジェクト: heynemann/wight
    def test_authenticating(self):
        user = UserFactory.create()

        exists, auth_user = User.authenticate(email=user.email, password="******")
        expect(exists).to_be_true()
        expect(auth_user).not_to_be_null()

        expect(auth_user.token).not_to_be_null()
        expect(auth_user.token_expiration).not_to_be_null()
コード例 #8
0
ファイル: test_user_model.py プロジェクト: movermeyer/wight
    def test_authenticating(self):
        user = UserFactory.create()

        exists, auth_user = User.authenticate(email=user.email,
                                              password="******")
        expect(exists).to_be_true()
        expect(auth_user).not_to_be_null()

        expect(auth_user.token).not_to_be_null()
        expect(auth_user.token_expiration).not_to_be_null()
コード例 #9
0
    def test_authenticate_with_valid_user(self):
        email = "*****@*****.**"
        password = "******"
        user = User(email=email, password=password)
        user.save()

        exists, user = User.authenticate(email=email, password=password)

        response = self.fetch_with_headers(self.reverse_url('auth_token'), token=user.token)
        expect(response.code).to_equal(200)
        expect(response.body).to_equal("OK")

        user = User.objects.filter(email=email).first()

        expect(response.headers).to_include('Token-Expiration')
        # without nano seconds
        expect(response.headers['Token-Expiration'][:19]).to_equal(user.token_expiration.isoformat()[:19])

        expect(response.headers).to_include('Token')
        expect(response.headers['Token']).to_equal(user.token)
コード例 #10
0
    def test_authenticate_with_valid_user(self):
        email = "*****@*****.**"
        password = "******"
        user = User(email=email, password=password)
        user.save()

        exists, user = User.authenticate(email=email, password=password)

        response = self.fetch_with_headers(self.reverse_url('auth_token'),
                                           token=user.token)
        expect(response.code).to_equal(200)
        expect(response.body).to_equal("OK")

        user = User.objects.filter(email=email).first()

        expect(response.headers).to_include('Token-Expiration')
        # without nano seconds
        expect(response.headers['Token-Expiration'][:19]).to_equal(
            user.token_expiration.isoformat()[:19])

        expect(response.headers).to_include('Token')
        expect(response.headers['Token']).to_equal(user.token)
コード例 #11
0
ファイル: authentication.py プロジェクト: movermeyer/wight
    def get(self):
        email = self.request.headers.get("Email", None)
        password = self.request.headers.get("Password", None)

        if not email or not password:
            self.set_status(400)
            self.finish()
            return

        user = User.create(email, password)

        if user is None:
            self.set_status(409)
            self.write("User already registered.")
            self.finish()
            return

        exists, user = User.authenticate(email, password)

        self.set_status(200)
        self.write("OK")
        self.set_header("Token", user.token)
        self.set_header("Token-Expiration", user.token_expiration.isoformat())
        self.finish()
コード例 #12
0
ファイル: authentication.py プロジェクト: heynemann/wight
    def get(self):
        email = self.request.headers.get("Email", None)
        password = self.request.headers.get("Password", None)

        if not email or not password:
            self.set_status(400)
            self.finish()
            return

        user = User.create(email, password)

        if user is None:
            self.set_status(409)
            self.write("User already registered.")
            self.finish()
            return

        exists, user = User.authenticate(email, password)

        self.set_status(200)
        self.write("OK")
        self.set_header("Token", user.token)
        self.set_header("Token-Expiration", user.token_expiration.isoformat())
        self.finish()