コード例 #1
0
 def test_identify_with_required_https(self):
     plugin = BrowserIDPlugin(["localhost"],
                              check_https=True,
                              check_referer=False)
     assertion = make_fake_assertion("*****@*****.**")
     body = "assertion=%s&csrf_token=123456" % (assertion, )
     # This one fails due to not being over https.
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
     self.assertEquals(environ[_ENVKEY_ERROR_MESSAGE],
                       "Login requests must use a secure connection")
     # This one still works OK.
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     environ["wsgi.url_scheme"] = "https"
     identity = plugin.identify(environ)
     self.assertEquals(identity["browserid.assertion"], assertion)
コード例 #2
0
 def test_identify_with_POST_vars(self):
     plugin = BrowserIDPlugin()
     body = "[email protected]"
     environ = make_environ(REQUEST_METHOD="POST", CONTENT_LENGTH=len(body))
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     # This fails since we're not at the postback url.
     self.assertEquals(identity, None)
     # This works since we're at the postback url.
     environ = make_environ(REQUEST_METHOD="POST", CONTENT_LENGTH=len(body), PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     self.assertEquals(identity["browserid.assertion"], "*****@*****.**")
コード例 #3
0
 def test_identify_with_missing_referer(self):
     plugin = BrowserIDPlugin(["localhost"])
     assertion = make_fake_assertion("*****@*****.**")
     body = "assertion=%s&csrf_token=123456" % (assertion,)
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     # By default we don't check referer for http connections.
     environ["wsgi.url_scheme"] = "http"
     identity = plugin.identify(environ)
     self.assertEquals(identity["browserid.assertion"], assertion)
     # But we do check them for https connections.
     environ["wsgi.url_scheme"] = "https"
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
コード例 #4
0
 def test_identify_with_missing_referer(self):
     plugin = BrowserIDPlugin(["localhost"])
     assertion = make_fake_assertion("*****@*****.**")
     body = "assertion=%s&csrf_token=123456" % (assertion, )
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     # By default we don't check referer for http connections.
     environ["wsgi.url_scheme"] = "http"
     identity = plugin.identify(environ)
     self.assertEquals(identity["browserid.assertion"], assertion)
     # But we do check them for https connections.
     environ["wsgi.url_scheme"] = "https"
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
コード例 #5
0
 def test_identify_with_POST_vars(self):
     plugin = BrowserIDPlugin(["localhost"])
     assertion = make_fake_assertion("*****@*****.**")
     body = "assertion=%s&csrf_token=123456" % (assertion, )
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body))
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     # This fails since we're not at the postback url.
     self.assertEquals(identity, None)
     # This works since we're at the postback url.
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     self.assertEquals(identity["browserid.assertion"], assertion)
コード例 #6
0
 def test_identify_with_GET_vars(self):
     plugin = BrowserIDPlugin(["localhost"])
     assertion = make_fake_assertion("*****@*****.**")
     query_string = "/?assertion=%s&csrf_token=123456" % (assertion,)
     environ = make_environ(REQUEST_METHOD="GET",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            PATH_INFO=plugin.postback_url,
                            QUERY_STRING=query_string)
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
コード例 #7
0
 def test_identify_with_POST_vars(self):
     plugin = BrowserIDPlugin(["localhost"])
     assertion = make_fake_assertion("*****@*****.**")
     body = "assertion=%s&csrf_token=123456" % (assertion,)
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body))
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     # This fails since we're not at the postback url.
     self.assertEquals(identity, None)
     # This works since we're at the postback url.
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     self.assertEquals(identity["browserid.assertion"], assertion)
コード例 #8
0
 def test_identify_with_GET_vars(self):
     plugin = BrowserIDPlugin(["localhost"])
     assertion = make_fake_assertion("*****@*****.**")
     query_string = "/?assertion=%s&csrf_token=123456" % (assertion, )
     environ = make_environ(REQUEST_METHOD="GET",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            PATH_INFO=plugin.postback_url,
                            QUERY_STRING=query_string)
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
コード例 #9
0
 def test_identify_with_missing_csrf(self):
     plugin = BrowserIDPlugin(None)
     assertion = make_fake_assertion("*****@*****.**")
     body = "assertion=%s&csrf_token=987654" % (assertion,)
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
コード例 #10
0
 def test_identify_with_missing_csrf(self):
     plugin = BrowserIDPlugin(None)
     assertion = make_fake_assertion("*****@*****.**")
     body = "assertion=%s&csrf_token=987654" % (assertion, )
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
コード例 #11
0
 def test_identify_with_malformed_assertion(self):
     plugin = BrowserIDPlugin(["localhost"])
     body = "assertion=%s&csrf_token=123456" % ("JUNK",)
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
     self.assertEquals(environ[_ENVKEY_ERROR_MESSAGE],
                       "Malformed BrowserID assertion")
コード例 #12
0
 def test_identify_with_malformed_assertion(self):
     plugin = BrowserIDPlugin(["localhost"])
     body = "assertion=%s&csrf_token=123456" % ("JUNK", )
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
     self.assertEquals(environ[_ENVKEY_ERROR_MESSAGE],
                       "Malformed BrowserID assertion")
コード例 #13
0
 def test_identify_with_required_https(self):
     plugin = BrowserIDPlugin(["localhost"], check_https=True,
                                             check_referer=False)
     assertion = make_fake_assertion("*****@*****.**")
     body = "assertion=%s&csrf_token=123456" % (assertion,)
     # This one fails due to not being over https.
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
     self.assertEquals(environ[_ENVKEY_ERROR_MESSAGE],
                       "Login requests must use a secure connection")
     # This one still works OK.
     environ = make_environ(REQUEST_METHOD="POST",
                            HTTP_COOKIE="browserid_csrf_token=123456",
                            CONTENT_LENGTH=len(body),
                            PATH_INFO=plugin.postback_url)
     environ["wsgi.input"] = StringIO(body)
     environ["wsgi.url_scheme"] = "https"
     identity = plugin.identify(environ)
     self.assertEquals(identity["browserid.assertion"], assertion)
コード例 #14
0
 def test_identify_with_authz_header(self):
     plugin = BrowserIDPlugin()
     authz = "BrowserID [email protected]"
     environ = make_environ(HTTP_AUTHORIZATION=authz)
     identity = plugin.identify(environ)
     self.assertEquals(identity["browserid.assertion"], "*****@*****.**")
コード例 #15
0
 def test_identify_with_GET_vars(self):
     plugin = BrowserIDPlugin()
     qs = "[email protected]"
     environ = make_environ(QUERY_STRING=qs)
     identity = plugin.identify(environ)
     self.assertEquals(identity["browserid.assertion"], "*****@*****.**")
コード例 #16
0
 def test_identify_with_no_credentials(self):
     plugin = BrowserIDPlugin(None)
     environ = make_environ()
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
コード例 #17
0
 def test_identify_with_no_credentials(self):
     plugin = BrowserIDPlugin(None)
     environ = make_environ()
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)
コード例 #18
0
 def test_identify_with_invalid_authz_header(self):
     plugin = BrowserIDPlugin()
     authz = "SomeOtherScheme [email protected]"
     environ = make_environ(HTTP_AUTHORIZATION=authz)
     identity = plugin.identify(environ)
     self.assertEquals(identity, None)