Exemple #1
0
    def test_QuerySid(self):
        """
        if no cookie, sess should read from the querystring
        """
        req = self.builder.build(querystring="weblib.Sess=ABC")
        sess = weblib.Sess(self.pool, req, weblib.Response())

        actual = sess._getSid()
        assert actual == "ABC", \
               "getSid doesn't read the querystring (fallback): %s" % actual
Exemple #2
0
    def test_CookieSid(self):
        """
        sess should read sid from the cookie.
        """
        req = self.builder.build(cookie={"weblib.Sess": "123"},
                                 querystring="weblib.Sess=ABC")
        sess = weblib.Sess(self.pool, req, weblib.Response())

        actual = sess._getSid()
        assert actual == "123", \
               "getSid doesn't read the cookie: %s.." % actual
Exemple #3
0
 def setUp(self):
     # auth requires a PATH_INFO variable.. otherwise,
     # it doesn't know where to redirect the form.
     #
     # @TODO: is PATH_INFO correct? I think standard might be SCRIPT_NAME
     #
     self.myReq = weblib.Request(environ={"PATH_INFO":"dummy.py"})
     self.myRes = weblib.Response()
     self.sess = weblib.Sess(weblib.SessPool.InMemorySessPool(),
                             self.myReq,
                             self.myRes)
Exemple #4
0
    def check_prompt(self):
        wres = weblib.Response()
        sess = weblib.Sess(weblib.SessPool.InMemorySessPool(), self.myReq,
                           wres)
        auth = zikebase.UserAuth(sess, self.ds)
        try:
            auth.check()
            gotExit = 0
        except SystemExit:
            gotExit = 1

        assert gotExit, \
               "should have demanded login"

        assert string.find(wres.buffer, auth.PLEASELOGIN) > -1, \
               "doesn't show prompt!"
Exemple #5
0
 def check_login_invalid(self):
     """
     Invalid login should show error, display form, and raise SystemExit.
     """
     req = weblib.Request(environ = {"PATH_INFO":"sadfaf"},
                          querystring="auth_check_flag=1",
                          form={"auth_username":"******",
                                "auth_password":"******"})
     sess = weblib.Sess(weblib.SessPool.InMemorySessPool(),
                        req, self.myRes)
     try:
         auth = weblib.Auth(sess, {'username':'******'})
         auth.check()
         gotExit = 0
     except SystemExit:
         gotExit = 1
     assert gotExit, \
            "invalid login didn't get SystemExit"
     assert string.find(self.myRes.buffer, auth.LOGINFAILED) > -1, \
            "invalid login doesn't give LOGINFAILED!"
Exemple #6
0
 def check_login_valid(self):
     """
     Valid login should have no side effects.
     """
     req = weblib.Request(environ = {"PATH_INFO":"sadfaf"},
                          querystring="auth_check_flag=1",
                          form={"auth_username":"******",
                                "auth_password":"******"})
     sess = weblib.Sess(weblib.SessPool.InMemorySessPool(),
                        req, self.myRes)
     try:
         auth = weblib.Auth(sess, {"username":"******"})
         auth.check()
         gotExit = 0
     except SystemExit:
         gotExit = 1
     assert self.myRes.buffer == "", \
            "valid login shouldn't output anything! [vs '%s']" \
            % self.myRes.buffer
     assert not gotExit, \
            "valid login still got SystemExit"
Exemple #7
0
 def setUp(self, sid=None):
     self.builder = weblib.RequestBuilder()
     self.pool = SessPool.InMemorySessPool({})
     self.sess = weblib.Sess(self.pool, self.builder.build(),
                             weblib.Response())
     self.sess.start(sid)