def site_for_options(reactor, options): provisioner = get_provisioner( reactor, options["subscription-manager"], provision_subscription, ) def get_signup(style): if style == u"wormhole": return get_wormhole_signup( reactor, provisioner, wormhole, options["rendezvous-url"], options["wormhole-result-path"], ) elif style == u"email": return get_email_signup( reactor, provisioner, send_signup_confirmation, send_notify_failure, ) else: raise ValueError( "Don't know about signup configuration {}".format( options["signup"], ), ) resource = make_resource( options["stripe-publishable-api-key-path"].getContent().strip(), get_signup, Stripe(options["stripe-secret-api-key-path"].getContent().strip()), Mailer(), ) site = make_site(resource, options["site-logs-path"]) return site
def _make_wormhole_claim(self, customer_email, customer_id, subscription_id, old_secrets): plan_identifier = u"foobar" reactor = Clock() provisioner = get_provisioner( reactor, URL.fromText(u"http://subscription-manager/"), partial(self._provision_subscription, old_secrets), ) server = MemoryWormholeServer() signup = get_wormhole_signup( reactor, provisioner, server, URL.fromText(u"ws://foo.invalid/"), FilePath(self.mktemp()), ) d = signup.signup( customer_email, customer_id, subscription_id, plan_identifier, ) return self.successResultOf(d)
def test_emailed_introducer_furl( self, customer_email, customer_id, subscription_id, old_secrets, introducer_port_number, storage_port_number, ): """ The email signup mechanism sends an activation email including an introducer furl which points at the server and port identified by the activated subscription detail object. """ assume(introducer_port_number != storage_port_number) emails = [] def provision_subscription( smclient, subscription, ): return succeed( attr.assoc( subscription, introducer_port_number=introducer_port_number, storage_port_number=storage_port_number, oldsecrets=old_secrets, ), ) def send_signup_confirmation( customer_email, external_introducer_furl, customer_keyinfo, stdout, stderr, ): emails.append((customer_email, "success", external_introducer_furl)) return succeed(None) def send_notify_failure( reason, customer_email, logfilename, stdout, stderr, ): emails.append((customer_email, "failure", reason)) return succeed(None) plan_identifier = u"foobar" reactor = object() signup = get_email_signup( reactor, get_provisioner( reactor, URL.fromText(u"http://subscription-manager/"), provision_subscription, ), send_signup_confirmation, send_notify_failure, ) d = signup.signup(customer_email, customer_id, subscription_id, plan_identifier) self.successResultOf(d) [(recipient, result, rest)] = emails self.expectThat(recipient, Equals(customer_email)) self.expectThat(result, Equals("success")) def get_hint_port(furl): tub_id, location_hints, name = decode_furl(furl) host, port = location_hints[0].split(u":") return int(port) self.expectThat( rest, AfterPreprocessing( get_hint_port, Equals(introducer_port_number), ), )
def test_wormhole_tahoe_configuration( self, customer_email, customer_id, subscription_id, old_secrets, introducer_port_number, storage_port_number, ): """ The wormhole signup mechanism sends a JSON blob of Tahoe-LAFS configuration via a magic wormhole identified by a wormhole code produced during signup. """ assume(introducer_port_number != storage_port_number) provisioned = [] def provision_subscription( smclient, subscription, ): p = attr.assoc( subscription, introducer_port_number=introducer_port_number, storage_port_number=storage_port_number, oldsecrets=old_secrets, ) provisioned.append(p) return succeed(p) plan_identifier = u"foobar" reactor = Clock() server = MemoryWormholeServer() provisioner = get_provisioner( reactor, URL.fromText(u"http://subscription-manager/"), provision_subscription, ) signup = get_wormhole_signup( reactor, provisioner, server, URL.fromText(u"ws://foo.invalid/"), FilePath(self.mktemp()), ) d = signup.signup(customer_email, customer_id, subscription_id, plan_identifier) wormhole_claim = self.successResultOf(d) wh = server.create( u"tahoe-lafs.org/tahoe-lafs/v1", u"ws://foo.invalid/", reactor, ) wh.set_code(wormhole_claim.code) d = wh.when_code() def foo(x): wh.send_message('{"abilities": {"client-v1": {}}}') return wh.get_message() d.addCallback(foo) def bar(arg): self.assertEqual( loads(arg), {"abilities": {"server-v1":{}}} ) return wh.get_message() d.addCallback(bar) received = self.successResultOf(d) received_config = loads(received) self.assertThat( received_config["introducer"], Equals(provisioned[0].external_introducer_furl), )
def site_for_options(reactor, options): provisioner = get_provisioner( reactor, options["subscription-manager"], provision_subscription, ) def get_signup(style): if style == u"wormhole": return get_wormhole_signup( reactor, provisioner, wormhole, options["rendezvous-url"], options["wormhole-result-path"], ) elif style == u"email": return get_email_signup( reactor, provisioner, send_signup_confirmation, send_notify_failure, ) else: raise ValueError( "Don't know about signup configuration {}".format( options["signup"], ), ) chargebee_secret_key = options[ "chargebee-secret-api-key-path" ].getContent().strip() resource = make_resource( options["stripe-publishable-api-key-path"].getContent().strip(), get_signup, ChargeBee( chargebee_secret_key, options["chargebee-site-name"], options["chargebee-gateway-account-id"], options["chargebee-plan-id"], ), Mailer( '*****@*****.**', options["signup-failure-address"] if options["signup-failure-address"] is not None else "*****@*****.**" if "www-staging" in options["cross-domain"] else "*****@*****.**" ), options["cross-domain"], ) # Expose some ChargeBee APIs, too. These cannot be queried by a browser # directly so we proxy them here. resource.putChild( "chargebee", create_chargebee_resources( reactor, options["chargebee-site-name"], chargebee_secret_key, options["chargebee-domain"], ), ) site = make_site( # Set the CORS header on all resources on this site. access_control_allow_origins( [options['cross-domain']], resource, ), options["site-logs-path"], ) return site
def test_wormhole_tahoe_configuration( self, customer_email, customer_id, subscription_id, old_secrets, introducer_port_number, storage_port_number, ): """ The wormhole signup mechanism sends a JSON blob of Tahoe-LAFS configuration via a magic wormhole identified by a wormhole code produced during signup. """ assume(introducer_port_number != storage_port_number) provisioned = [] def provision_subscription( smclient, subscription, ): p = attr.assoc( subscription, introducer_port_number=introducer_port_number, storage_port_number=storage_port_number, oldsecrets=old_secrets, ) provisioned.append(p) return succeed(p) plan_identifier = u"foobar" reactor = Clock() server = MemoryWormholeServer() provisioner = get_provisioner( reactor, URL.fromText(u"http://subscription-manager/"), provision_subscription, ) signup = get_wormhole_signup( reactor, provisioner, server, URL.fromText(u"ws://foo.invalid/"), FilePath(self.mktemp()), ) d = signup.signup(customer_email, customer_id, subscription_id, plan_identifier) wormhole_claim = self.successResultOf(d) wh = server.create( APPID, u"ws://foo.invalid/", reactor, ) wh.set_code(wormhole_claim.code) d = wh.when_code() def foo(x): wh.send_message('{"abilities": {"client-v1": {}}}') return wh.get_message() d.addCallback(foo) def bar(arg): self.assertEqual( loads(arg), {"abilities": {"server-v1":{}}} ) return wh.get_message() d.addCallback(bar) received = self.successResultOf(d) received_config = loads(received) self.assertThat( received_config["introducer"], Equals(provisioned[0].external_introducer_furl), )