Example #1
0
 def test_simple_login(self):
     backend = MongoDBRegistrationBackend(self.settings, self.config)
     # Test good, available username, writing it to DB
     password = "******"
     struct = {"username":"******", "password":password, "email":"*****@*****.**"}
     backend.add_user(struct)
     # Now lets verify we can retrieve it correctly with a simple_login
     user_doc = backend.simple_login(struct["username"], struct["password"])
     self.assertEquals(struct["username"], user_doc["username"])
     self.assertEquals(struct["email"], user_doc["email"])
     # Same again but by email not username
     user_doc = backend.simple_login(struct["email"], struct["password"])
     self.assertEquals(struct["username"], user_doc["username"])
     self.assertEquals(struct["email"], user_doc["email"])
     # Failure case: bad password
     user_doc = backend.simple_login(struct["email"], "wrongpassword")
     self.assertFalse(user_doc)
Example #2
0
    def test_simple_login(self, connection_mock):
        conn = connection_mock.instance()
        connection_mock.return_value = conn
        db = conn[self.settings["mongodb.db_name"]]
        backend = MongoDBRegistrationBackend(self.settings, self.config)

        password = "******"
        stored_user = {"username":"******",
                "password":_hash_pw("testpassword"),
                "email":"*****@*****.**"}

        # Test situation where user exists and we do password hash comparison
        db.users.find_one.return_value = stored_user
        self.assertTrue(backend.simple_login(stored_user["username"], password))

        # Test situation where user does not exist
        db.users.find_one.return_value = False
        self.assertFalse(backend.simple_login(stored_user["username"], password))
Example #3
0
 def test_simple_login(self):
     backend = MongoDBRegistrationBackend(self.settings, self.config)
     # Test good, available username, writing it to DB
     password = "******"
     struct = {
         "username": "******",
         "password": password,
         "email": "*****@*****.**"
     }
     backend.add_user(struct)
     # Now lets verify we can retrieve it correctly with a simple_login
     user_doc = backend.simple_login(struct["username"], struct["password"])
     self.assertEquals(struct["username"], user_doc["username"])
     self.assertEquals(struct["email"], user_doc["email"])
     # Same again but by email not username
     user_doc = backend.simple_login(struct["email"], struct["password"])
     self.assertEquals(struct["username"], user_doc["username"])
     self.assertEquals(struct["email"], user_doc["email"])
     # Failure case: bad password
     user_doc = backend.simple_login(struct["email"], "wrongpassword")
     self.assertFalse(user_doc)
Example #4
0
    def test_simple_login(self, connection_mock):
        conn = connection_mock.instance()
        connection_mock.return_value = conn
        db = conn[self.settings["mongodb.db_name"]]
        backend = MongoDBRegistrationBackend(self.settings, self.config)

        password = "******"
        stored_user = {
            "username": "******",
            "password": _hash_pw("testpassword"),
            "email": "*****@*****.**"
        }

        # Test situation where user exists and we do password hash comparison
        db.users.find_one.return_value = stored_user
        self.assertTrue(backend.simple_login(stored_user["username"],
                                             password))

        # Test situation where user does not exist
        db.users.find_one.return_value = False
        self.assertFalse(
            backend.simple_login(stored_user["username"], password))