Example #1
0
    def setUp(self):
        """Launch app using webtest with test settings"""
        self.appconf = get_app(test_ini)
        self.app = TestApp(self.appconf)

        #All auth via BasicAuth - never return the session cookie.
        self.app.cookiejar.set_policy(DefaultCookiePolicy(allowed_domains=[]))

        # This sets global var "engine" - in the case of SQLite this is a fresh RAM
        # DB each time.  If we only did this on class instantiation the database would
        # be dirty and one test could influence another.
        # TODO - add a test that tests this.
        server.choose_engine("SQLite")

        # Punch in new user account with direct server call
        # This will implicitly generate the tables.
        user_id = self.create_user("testuser")
        #Here is what the user should look like when inspected
        self.user_json =  { "name"    : "testuser testuser",
                            "handle"  : "*****@*****.**",
                            "id"      : 1,
                            "credits" : 0,
                            "username": "******"}

        #print("user_id is %s" % str(user_id))
        #print("user_from_db_is %s" % server.get_user_id_from_name("testuser"))

        server.touch_to_add_password(user_id, "asdf")

        # And log in as this user for all tests (via BasicAuth)
        # FIXME - switch to token auth to speed up the tests.
        self.app.authorization = ('Basic', ('testuser', 'asdf'))
Example #2
0
    def setUp(self):
        """Launch pserve using webtest with test settings"""
        self.appconf = get_app(test_ini)
        self.app = TestApp(self.appconf)

        #For speed, allow cookie setting.
        # self.app.cookiejar.set_policy(DefaultCookiePolicy(allowed_domains=[]))

        # This sets global var "engine" - in the case of SQLite this is a fresh RAM
        # DB each time.  If we only did this on class instantiation the database would
        # be dirty and one test could influence another.
        # TODO - add a test that tests this.
        server.choose_engine("SQLite")

        # Punch in new administrator account with direct server call
        # This will implicitly generate the tables.
        user_id = server.create_user("administrators", "administrator", "administrator", "administrator")
        #server.touch_to_add_user_group("administrator", "administrators")
        server.touch_to_add_password(user_id, "adminpass")

        self.app.authorization = ('Basic', ('administrator', 'adminpass'))

        # This sorts out the auth token cookie.
        self.app.get('/users')
        self.app.authorization = None
    def test_servers_badpass(self):
        """Likewise if I give a valid user name but no password
        """
        user_id = server.create_user("administrators", "administrator", "administrator", "administrator")
        #server.touch_to_add_user_group("administrator", "administrators")
        server.touch_to_add_password(user_id, "adminpass")

        app = self.testapp
        app.authorization = ('Basic', ('administrator', 'badpassword'))

        response = app.get('/servers', status=401)

        self.assertEqual(response.headers.get('WWW-Authenticate', 'empty'), 'Basic realm="eos_db"')
    def test_servers_badpass(self):
        """Likewise if I give a valid user name but no password
        """
        user_id = server.create_user("administrators", "administrator",
                                     "administrator", "administrator")
        #server.touch_to_add_user_group("administrator", "administrators")
        server.touch_to_add_password(user_id, "adminpass")

        app = self.testapp
        app.authorization = ('Basic', ('administrator', 'badpassword'))

        response = app.get('/servers', status=401)

        self.assertEqual(response.headers.get('WWW-Authenticate', 'empty'),
                         'Basic realm="eos_db"')
Example #5
0
def create_user_password(request):
    """ Creates a password for the user given. """
    username = request.matchdict['name']
    actor_id = server.get_user_id_from_name(username)
    newname = server.touch_to_add_password(actor_id, request.POST['password'])
    #FIXME - should we not just return OK?
    return newname
Example #6
0
def create_user_password(request):
    """ Creates a password for the user given. """
    username = request.matchdict["name"]
    actor_id = server.get_user_id_from_name(username)
    newname = server.touch_to_add_password(actor_id, request.POST["password"])
    # FIXME - should we not just return OK?
    return newname
Example #7
0
def create_my_password(request):
    """ Creates a password for the user given. """
    username = request.authenticated_userid
    actor_id = server.get_user_id_from_name(username)
    newname = server.touch_to_add_password(actor_id, request.POST['password'])
    #FIXME - should we not just return OK?
    #FIXME2 - also should this not be a POST?
    return newname
Example #8
0
def create_my_password(request):
    """ Creates a password for the user given. """
    username = request.authenticated_userid
    actor_id = server.get_user_id_from_name(username)
    newname = server.touch_to_add_password(actor_id, request.POST["password"])
    # FIXME - should we not just return OK?
    # FIXME2 - also should this not be a POST?
    return newname
Example #9
0
    def setUp(self):
        """Launch pserve using webtest with test settings"""
        self.appconf = get_app(test_ini)
        self.app = TestApp(self.appconf)

        # Punch in new administrator account with direct server call

        server.choose_engine("SQLite")  # Sets global var "engine" - in the
                                        # case of SQLite this is a fresh RAM
                                        # DB each time.

        # Create new user. This will implicitly generate the tables.
        id1 = server.create_user(None, "testuser", "testuser", "testuser")
        server.touch_to_add_user_group("testuser", "users")
        server.touch_to_add_password(id1, "testpass")

        id2 = server.create_user(None, "administrator", "administrator", "administrator")
        server.touch_to_add_user_group("administrator", "administrators")
        server.touch_to_add_password(id2, "adminpass")
Example #10
0
    def setUp(self):
        """Launch pserve using webtest with test settings"""
        self.appconf = get_app(test_ini)
        self.app = TestApp(self.appconf)

        # Punch in new administrator account with direct server call

        server.choose_engine("SQLite")  # Sets global var "engine" - in the
        # case of SQLite this is a fresh RAM
        # DB each time.

        # Create new user. This will implicitly generate the tables.
        id1 = server.create_user(None, "testuser", "testuser", "testuser")
        server.touch_to_add_user_group("testuser", "users")
        server.touch_to_add_password(id1, "testpass")

        id2 = server.create_user(None, "administrator", "administrator",
                                 "administrator")
        server.touch_to_add_user_group("administrator", "administrators")
        server.touch_to_add_password(id2, "adminpass")