コード例 #1
0
    def _test_devpaypurchasehandler(self, method):
        out = StringIO()
        config = Config(StringIO(SITE_CONFIG_JSON))

        d = devpay_complete.start(self.basefp)
        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.DevPayPurchaseHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY"], ProductCode=["PRODUCTCODE"]))

        def _finished( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('name="ActivationKey" value="ACTIVATIONKEY"', output)
            self.failUnlessIn('name="ProductCode" value="PRODUCTCODE"', output)
            self.failUnlessIn("ACTIVATIONKEY,PRODUCTCODE\n",
                              FilePath("devpay_completions.csv").getContent())
        d.addCallback(_finished)
        return d
コード例 #2
0
    def _test_devpaypurchasehandler(self, method):
        out = StringIO()
        config = Config(StringIO(SITE_CONFIG_JSON))

        d = devpay_complete.start(self.basefp)
        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.DevPayPurchaseHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY"], ProductCode=["PRODUCTCODE"]))

        def _finished( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('name="ActivationKey" value="ACTIVATIONKEY"', output)
            self.failUnlessIn('name="ProductCode" value="PRODUCTCODE"', output)
            self.failUnlessIn("ACTIVATIONKEY,PRODUCTCODE\n",
                              FilePath("devpay_completions.csv").getContent())
        d.addCallback(_finished)
        return d
コード例 #3
0
ファイル: main.py プロジェクト: almet/leastauthority.com
    if ssl_enabled:
        logging.info('SSL/TLS is enabled (start with --nossl to disable).')
        KEYFILE = '../secret_config/rapidssl/server.key'
        CERTFILE = '../secret_config/rapidssl/server.crt'
        assert os.path.exists(KEYFILE), "Private key file %s not found" % (KEYFILE,)
        assert os.path.exists(CERTFILE), "Certificate file %s not found" % (CERTFILE,)

        # http://twistedmatrix.com/documents/current/core/howto/ssl.html
        sslfactory = ssl.DefaultOpenSSLContextFactory(KEYFILE, CERTFILE)
        reactor.listenSSL(port, site, sslfactory)

        if redirect_port is not None:
            logging.info('http->https redirector listening on port %d...' % (redirect_port,))
            reactor.listenTCP(redirect_port, make_redirector_site(port))
    else:
        logging.info('SSL/TLS is disabled.')
        reactor.listenTCP(port, site)


if __name__ == '__main__':
    basefp = FilePath('..')
    def _err(f):
        print f
        return f

    d = start(basefp)
    d.addCallback(lambda ign: main(basefp))
    d.addErrback(_err)
    d.addErrback(lambda ign: os._exit(1))
    reactor.run()
コード例 #4
0
    def test_collectemailhandler(self):
        out = StringIO()
        config = Config(StringIO(SITE_CONFIG_JSON))
        self.email_content = None

        def call_send_plain_email(fromEmail, toEmail, content, headers):
            self.email_content = content
        self.patch(send_email, 'send_plain_email', call_send_plain_email)
        self.patch(devpay_complete, 'send_plain_email', call_send_plain_email)

        d = devpay_complete.start(self.basefp)
        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.CollectEmailHandler(self.basefp, config.products, out=out),
                                         "POST", Email=["*****@*****.**"], ProductName=["future"],
                                         ProductFullName=["Voyage to Tau Ceti"]))

        def _finished_future( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('Thank you for your interest in Voyage to Tau Ceti!', output)
            self.failIfIn('<a href="/signup/future">', output)
            self.failUnlessIn("We've just sent you an email", output)
            self.failIfIn("https://leastauthority.com/signup/", self.email_content)
            self.failUnlessIn("[email protected],future\n",
                              FilePath("emails.csv").getContent())
            remove_if_possible(self.basefp.child("emails.csv"))
            self.email_content = None
        d.addCallback(_finished_future)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.CollectEmailHandler(self.basefp, config.products, out=out),
                                         "POST", Email=["*****@*****.**"], ProductName=["product"],
                                         ProductFullName=["Yummy cloud hotness"]))

        def _finished_valid( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('Thank you for your interest in Yummy cloud hotness!', output)
            self.failUnlessIn('<a href="/signup/product">', output)
            self.failUnlessIn("We've just sent you an email", output)
            self.failUnlessIn("https://leastauthority.com/signup/product", self.email_content)
            self.failUnlessIn("[email protected],product\n",
                              FilePath("emails.csv").getContent())
            remove_if_possible(self.basefp.child("emails.csv"))
            self.email_content = None
        d.addCallback(_finished_valid)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.CollectEmailHandler(self.basefp, config.products, out=out),
                                         "POST", Email=["blah"], ProductName=["product"],
                                         ProductFullName=["Yummy cloud hotness"]))
        def _finished_invalid( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('Thank you for your interest in Yummy cloud hotness, but', output)
            self.failIfIn('<a href="/signup/product">', output)
            self.failIf(self.email_content)
            self.failUnlessIn('<a href="/">', output)
            self.failUnlessIn("blah,product\n",
                              FilePath("emails.csv").getContent())
            remove_if_possible(self.basefp.child("emails.csv"))
            self.email_content = None
        d.addCallback(_finished_invalid)

        def call_send_plain_email_broken(fromEmail, toEmail, content, headers):
            raise Exception("something went wrong")
        d.addCallback(lambda ign: self.patch(send_email, 'send_plain_email', call_send_plain_email_broken))
        d.addCallback(lambda ign: self.patch(devpay_complete, 'send_plain_email', call_send_plain_email_broken))

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.CollectEmailHandler(self.basefp, config.products, out=out),
                                         "POST", Email=["*****@*****.**"], ProductName=["product"],
                                         ProductFullName=["Yummy cloud hotness"]))

        def _finished_could_not_send( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('Thank you for your interest in Yummy cloud hotness!', output)
            self.failUnlessIn('<a href="/signup/product">', output)
            self.failUnlessIn("We weren't able to send email", output)
            self.failIf(self.email_content)
            self.failUnlessIn("[email protected],product\n",
                              FilePath("emails.csv").getContent())
            remove_if_possible(self.basefp.child("emails.csv"))
            self.email_content = None
        d.addCallback(_finished_could_not_send)
        return d
コード例 #5
0
    def _test_activationrequesthandler(self, method):
        out = StringIO()
        config = Config(StringIO(SITE_CONFIG_JSON))

        d = devpay_complete.start(self.basefp)
        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY"], ProductCode=["PRODUCTCODE"],
                                         Name=["Joe & Mildred"], Email=["*****@*****.**"], PublicKey=["===BEGIN BLAH==="]))

        def _finished( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Activation requested</title>", output)
            self.failUnlessIn("Your Simple Secure Storage Service has been activated", output)
            self.failUnlessIn(",ACTIVATIONKEY,PRODUCTCODE,Joe %26 Mildred,[email protected],===BEGIN BLAH===\n",
                              FilePath("activation_requests.csv").getContent())
            self.failUnlessIn(",success,ACTIVATIONKEY,PRODUCTCODE,Joe %26 Mildred,[email protected],===BEGIN BLAH===\n",
                              FilePath("signups.csv").getContent())
        d.addCallback(_finished)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY"], ProductCode=["PRODUCTCODE"],
                                         Name=["Joe & Mildred"], Email=["*****@*****.**"], PublicKey=["===BEGIN BLAH==="]))

        def _finished_again( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Activation already succeeded</title>", output)

            devpay_complete.flappcommand.should_succeed = False
        d.addCallback(_finished_again)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY2"], ProductCode=["PRODUCTCODE"],
                                         Name=[""], Email=["*****@*****.**"], PublicKey=["===BEGIN BLAH==="]))
        def _no_name( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Missing name</title>", output)
            self.failUnlessIn("The 'Name' field was not filled in", output)
            self.failUnlessIn(",ACTIVATIONKEY2,PRODUCTCODE,,[email protected],===BEGIN BLAH===\n",
                              FilePath("activation_requests.csv").getContent())
            self.failIfIn("ACTIVATIONKEY2", FilePath("signups.csv").getContent())
        d.addCallback(_no_name)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY3"], ProductCode=["PRODUCTCODE"],
                                         Name=["Joe & Mildred"], Email=["joe&[email protected]"], PublicKey=["===BEGIN BLAH==="]))
        def _bad_email( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Missing or invalid email address</title>", output)
            self.failUnlessIn("The 'Email address' field was not filled in with a valid-looking address", output)
            self.failUnlessIn(",ACTIVATIONKEY3,PRODUCTCODE,Joe %26 Mildred,joe%[email protected],===BEGIN BLAH===\n",
                              FilePath("activation_requests.csv").getContent())
            self.failIfIn("ACTIVATIONKEY3", FilePath("signups.csv").getContent())
        d.addCallback(_bad_email)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY4"], ProductCode=["PRODUCTCODE"],
                                         Name=["Joe & Mildred"], Email=["*****@*****.**"], PublicKey=["===BEGIN BLAH==="]))
        def _finished_error( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Activation requested</title>", output)
            self.failUnlessIn("We weren't able to complete your account activation automatically", output)
            self.failUnlessIn(",ACTIVATIONKEY4,PRODUCTCODE,Joe %26 Mildred,[email protected],===BEGIN BLAH===\n",
                              FilePath("activation_requests.csv").getContent())
            self.failUnlessIn(",failure,ACTIVATIONKEY4,PRODUCTCODE,Joe %26 Mildred,[email protected],===BEGIN BLAH===\n",
                              FilePath("signups.csv").getContent())
        d.addCallback(_finished_error)
        return d
コード例 #6
0
    def test_collectemailhandler(self):
        out = StringIO()
        config = Config(StringIO(SITE_CONFIG_JSON))
        self.email_content = None

        def call_send_plain_email(fromEmail, toEmail, content, headers):
            self.email_content = content
        self.patch(send_email, 'send_plain_email', call_send_plain_email)
        self.patch(devpay_complete, 'send_plain_email', call_send_plain_email)

        d = devpay_complete.start(self.basefp)
        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.CollectEmailHandler(self.basefp, config.products, out=out),
                                         "POST", Email=["*****@*****.**"], ProductName=["future"],
                                         ProductFullName=["Voyage to Tau Ceti"]))

        def _finished_future( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('Thank you for your interest in Voyage to Tau Ceti!', output)
            self.failIfIn('<a href="/signup/future">', output)
            self.failUnlessIn("We've just sent you an email", output)
            self.failIfIn("https://leastauthority.com/signup/", self.email_content)
            self.failUnlessIn("[email protected],future\n",
                              FilePath("emails.csv").getContent())
            remove_if_possible(self.basefp.child("emails.csv"))
            self.email_content = None
        d.addCallback(_finished_future)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.CollectEmailHandler(self.basefp, config.products, out=out),
                                         "POST", Email=["*****@*****.**"], ProductName=["product"],
                                         ProductFullName=["Yummy cloud hotness"]))

        def _finished_valid( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('Thank you for your interest in Yummy cloud hotness!', output)
            self.failUnlessIn('<a href="/signup/product">', output)
            self.failUnlessIn("We've just sent you an email", output)
            self.failUnlessIn("https://leastauthority.com/signup/product", self.email_content)
            self.failUnlessIn("[email protected],product\n",
                              FilePath("emails.csv").getContent())
            remove_if_possible(self.basefp.child("emails.csv"))
            self.email_content = None
        d.addCallback(_finished_valid)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.CollectEmailHandler(self.basefp, config.products, out=out),
                                         "POST", Email=["blah"], ProductName=["product"],
                                         ProductFullName=["Yummy cloud hotness"]))
        def _finished_invalid( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('Thank you for your interest in Yummy cloud hotness, but', output)
            self.failIfIn('<a href="/signup/product">', output)
            self.failIf(self.email_content)
            self.failUnlessIn('<form action="/collect-email"', output)
            self.failUnlessIn("blah,product\n",
                              FilePath("emails.csv").getContent())
            remove_if_possible(self.basefp.child("emails.csv"))
            self.email_content = None
        d.addCallback(_finished_invalid)

        def call_send_plain_email_broken(fromEmail, toEmail, content, headers):
            raise Exception("something went wrong")
        d.addCallback(lambda ign: self.patch(send_email, 'send_plain_email', call_send_plain_email_broken))
        d.addCallback(lambda ign: self.patch(devpay_complete, 'send_plain_email', call_send_plain_email_broken))

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.CollectEmailHandler(self.basefp, config.products, out=out),
                                         "POST", Email=["*****@*****.**"], ProductName=["product"],
                                         ProductFullName=["Yummy cloud hotness"]))

        def _finished_could_not_send( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn('Thank you for your interest in Yummy cloud hotness!', output)
            self.failUnlessIn('<a href="/signup/product">', output)
            self.failUnlessIn("We weren't able to send email", output)
            self.failIf(self.email_content)
            self.failUnlessIn("[email protected],product\n",
                              FilePath("emails.csv").getContent())
            remove_if_possible(self.basefp.child("emails.csv"))
            self.email_content = None
        d.addCallback(_finished_could_not_send)
        return d
コード例 #7
0
    def _test_activationrequesthandler(self, method):
        out = StringIO()
        config = Config(StringIO(SITE_CONFIG_JSON))

        d = devpay_complete.start(self.basefp)
        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY"], ProductCode=["PRODUCTCODE"],
                                         Name=["Joe & Mildred"], Email=["*****@*****.**"], PublicKey=["===BEGIN BLAH==="]))

        def _finished( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Activation requested</title>", output)
            self.failUnlessIn("Your Simple Secure Storage Service has been activated", output)
            self.failUnlessIn(",ACTIVATIONKEY,PRODUCTCODE,Joe %26 Mildred,[email protected],===BEGIN BLAH===\n",
                              FilePath("activation_requests.csv").getContent())
            self.failUnlessIn(",success,ACTIVATIONKEY,PRODUCTCODE,Joe %26 Mildred,[email protected],===BEGIN BLAH===\n",
                              FilePath("signups.csv").getContent())
        d.addCallback(_finished)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY"], ProductCode=["PRODUCTCODE"],
                                         Name=["Joe & Mildred"], Email=["*****@*****.**"], PublicKey=["===BEGIN BLAH==="]))

        def _finished_again( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Activation already succeeded</title>", output)

            devpay_complete.flappcommand.should_succeed = False
        d.addCallback(_finished_again)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY2"], ProductCode=["PRODUCTCODE"],
                                         Name=[""], Email=["*****@*****.**"], PublicKey=["===BEGIN BLAH==="]))
        def _no_name( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Missing name</title>", output)
            self.failUnlessIn("The 'Name' field was not filled in", output)
            self.failUnlessIn(",ACTIVATIONKEY2,PRODUCTCODE,,[email protected],===BEGIN BLAH===\n",
                              FilePath("activation_requests.csv").getContent())
            self.failIfIn("ACTIVATIONKEY2", FilePath("signups.csv").getContent())
        d.addCallback(_no_name)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY3"], ProductCode=["PRODUCTCODE"],
                                         Name=["Joe & Mildred"], Email=["joe&[email protected]"], PublicKey=["===BEGIN BLAH==="]))
        def _bad_email( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Missing or invalid email address</title>", output)
            self.failUnlessIn("The 'Email address' field was not filled in with a valid-looking address", output)
            self.failUnlessIn(",ACTIVATIONKEY3,PRODUCTCODE,Joe %26 Mildred,joe%[email protected],===BEGIN BLAH===\n",
                              FilePath("activation_requests.csv").getContent())
            self.failIfIn("ACTIVATIONKEY3", FilePath("signups.csv").getContent())
        d.addCallback(_bad_email)

        d.addCallback(lambda ign:
                      self._mock_request(devpay_complete.ActivationRequestHandler(self.basefp, config.products, out=out),
                                         method, ActivationKey=["ACTIVATIONKEY4"], ProductCode=["PRODUCTCODE"],
                                         Name=["Joe & Mildred"], Email=["*****@*****.**"], PublicKey=["===BEGIN BLAH==="]))
        def _finished_error( (req, output) ):
            self.failUnlessEqual(req.responsecode, OK)
            self.failUnlessIn("<title>Activation requested</title>", output)
            self.failUnlessIn("We weren't able to complete your account activation automatically", output)
            self.failUnlessIn(",ACTIVATIONKEY4,PRODUCTCODE,Joe %26 Mildred,[email protected],===BEGIN BLAH===\n",
                              FilePath("activation_requests.csv").getContent())
            self.failUnlessIn(",failure,ACTIVATIONKEY4,PRODUCTCODE,Joe %26 Mildred,[email protected],===BEGIN BLAH===\n",
                              FilePath("signups.csv").getContent())
        d.addCallback(_finished_error)
        return d