コード例 #1
0
    def test_agent(self):
        payload = {
            "username": "******",
            "password": "******",
            "agent": {"name": "Minecraft", "version": 1}
        }
        req.Authenticate(json.dumps(payload))

        payload["agent"]["name"] = 123
        with self.assertRaises(exc.BadPayload):
            req.Authenticate(json.dumps(payload))
コード例 #2
0
    def test_empty_credentials(self):
        with self.assertRaises(exc.EmptyCredentials):
            payload = json.dumps({})
            req.Authenticate(payload)

        with self.assertRaises(exc.EmptyCredentials):
            payload = json.dumps({"username": "******"})
            req.Authenticate(payload)

        with self.assertRaises(exc.EmptyCredentials):
            payload = json.dumps({"password": "******"})
            req.Authenticate(payload)
コード例 #3
0
    def test_client_token(self):
        payload = {
            "username": "******",
            "password": "******",
            "clientToken": generate_token()
        }
        req.Authenticate(json.dumps(payload))

        payload["clientToken"] = ""
        with self.assertRaises(exc.BadPayload):
            req.Authenticate(json.dumps(payload))

        payload["clientToken"] = {12: 34}
        with self.assertRaises(exc.BadPayload):
            req.Authenticate(json.dumps(payload))
コード例 #4
0
    def test_success_refresh(self):
        payload = {
            "username": "******",
            "password": "******",
        }
        request = req.Authenticate(json.dumps(payload))
        request.process()
        result = request.result
        token = Token.query.filter(Token.client == result["clientToken"]).one()
        old_token_values = (token.access, token.client)

        refresh_request = req.Refresh(json.dumps(result))
        refresh_request.process()
        refresh_result = refresh_request.result
        fresh_token = (
            Token.query
            .filter(Token.client == refresh_result["clientToken"])
            .one()
        )
        new_token_values = (token.access, token.client)

        self.assertNotEqual(result, fresh_token)
        self.assertNotEqual(old_token_values, new_token_values)

        self.assertEqual(refresh_result["accessToken"], token.access)
        self.assertEqual(refresh_result["clientToken"], token.client)
コード例 #5
0
 def test_wrong_password(self):
     payload = {
         "username": "******",
         "password": "******",
     }
     with self.assertRaises(exc.InvalidCredentials):
         request = req.Authenticate(json.dumps(payload))
         request.process()
コード例 #6
0
 def test_no_such_user(self):
     payload = {
         "username": "******",
         "password": "******",
     }
     with self.assertRaises(exc.InvalidCredentials):
         request = req.Authenticate(json.dumps(payload))
         request.process()
コード例 #7
0
 def test_migration_done(self):
     payload = {
         "username": "******",
         "password": "******",
     }
     with self.assertRaises(exc.MigrationDone):
         request = req.Authenticate(json.dumps(payload))
         request.process()
コード例 #8
0
    def test_nonstring_credentials(self):
        values = (123, True, [1], {2: 3})
        users = product(["username"], values)
        passwords = product(["password"], values)
        pairs = list(product(list(users), list(passwords)))
        probes = [dict(pair) for pair in pairs]

        for pair in probes:
            with self.assertRaises(exc.InvalidCredentials):
                req.Authenticate(json.dumps(pair))
コード例 #9
0
    def test_successful_validate(self):
        payload = {
            "username": "******",
            "password": "******"
        }
        request = req.Authenticate(json.dumps(payload))
        request.process()

        payload = {"accessToken": request.result["accessToken"]}
        request = req.Validate(json.dumps(payload))
        request.process()
コード例 #10
0
    def test_success_custom_client_token(self):
        payload = {
            "username": "******",
            "password": "******",
            "clientToken": generate_token()
        }
        request = req.Authenticate(json.dumps(payload))
        request.process()
        result = request.result

        self.assertIn("clientToken", result)
        self.assertEqual(payload["clientToken"], result["clientToken"])
コード例 #11
0
    def authenticate(raw_data):
        """Authenticate endpoint

        .. note::
            URL: /authenticate

        :type raw_data: bytes
        :rtype: str
        :return: JSON-encoded dict
        """

        instance = req.Authenticate(raw_data)
        instance.process()
        return instance.result
コード例 #12
0
    def test_success_simple(self):
        payload = {
            "username": "******",
            "password": "******",
        }
        request = req.Authenticate(json.dumps(payload))
        request.process()
        result = request.result
        user = User.query.filter(User.email == payload["username"]).one()

        self.assertIn("accessToken", result)
        self.assertIn("clientToken", result)
        self.assertEqual(result["accessToken"], user.token.access)
        self.assertEqual(result["clientToken"], user.token.client)
コード例 #13
0
    def test_successful_invalidate(self):
        payload = {
            "username": "******",
            "password": "******"
        }
        user = User.query.filter(User.email == payload["username"]).one()
        token_id = user.token.id

        request = req.Authenticate(json.dumps(payload))
        request.process()
        result = request.result

        invalidate_request = req.Invalidate(json.dumps(result))
        invalidate_request.process()

        self.assertIsNone(user.token)
        self.assertIsNone(Token.query.get(token_id))
コード例 #14
0
    def test_success_agent_profiles(self):
        payload = {
            "username": "******",
            "password": "******",
            "agent": {"name": "Minecraft", "version": 1}
        }
        request = req.Authenticate(json.dumps(payload))
        request.process()
        result = request.result

        user = User.query.filter(User.email == payload["username"]).one()
        profile = {"id": user.token.client, "name": user.login}

        self.assertIn("selectedProfile", result)
        self.assertEqual(result["selectedProfile"], profile)

        self.assertIn("availableProfiles", result)
        self.assertEqual(result["availableProfiles"], [profile])