def _addClientService(self, username, privateSecret, serverService, serverDomain): svc = self._makeQ2QService(username + '@' + serverDomain, None) serverService.certificateStorage.addUser(serverDomain, username, privateSecret) svc.setServiceParent(self.msvc) return svc.authorize(q2q.Q2QAddress(serverDomain, username), privateSecret).addCallback(lambda x: svc)
def setUp(self): self.fromAddress = q2q.Q2QAddress(self.fromDomain, self.fromResource) self.toAddress = q2q.Q2QAddress(self.toDomain, self.toResource) # A mapping of host names to port numbers Our connectTCP will always # connect to 127.0.0.1 and on a port which is a value in this # dictionary. fakeDNS = FakeConnectTCP(reactor.connectTCP) reactor.connectTCP = fakeDNS.connectTCP # ALSO WE MUST DO OTHER SIMILAR THINGS self._oldResolver = reactor.resolver reactor.installResolver(fakeDNS) # Set up a know-nothing service object for the client half of the # conversation. self.serverService2 = self._makeQ2QService(self.fromDomain, self.fromIP, noResources) # Do likewise for the server half of the conversation. Also, allow # test methods to set up some trivial resources which we can attempt to # access from the client. self.resourceMap = {} self.serverService = self._makeQ2QService(self.toDomain, self.toIP, self.protocolFactoryLookup) self.msvc = service.MultiService() self.serverService2.setServiceParent(self.msvc) self.serverService.setServiceParent(self.msvc) # Let the kernel allocate a random port for each of # these service's listeners self.msvc.startService() fakeDNS.addHostPort(self.fromDomain, 8788, self.serverService2.q2qPort.getHost().port) fakeDNS.addHostPort(self.toDomain, 8788, self.serverService.q2qPort.getHost().port) self._addQ2QProtocol('pony', OneTrickPonyServerFactory()) self.dataEater = DataEater() self._addQ2QProtocol('eat', self.dataEater) self._addQ2QProtocol('error', ErroneousServerFactory())
def enregister(svc, newAddress, password): """ Register a new account and return a Deferred that fires if it worked. @param svc: a Q2QService @param newAddress: a Q2QAddress object @param password: a shared secret (str) """ return svc.connectQ2Q(q2q.Q2QAddress("", ""), q2q.Q2QAddress(newAddress.domain, "accounts"), 'identity-admin', protocol.ClientFactory.forProtocol(AMP)).addCallback( AMP.callRemote, AddUser, name=newAddress.resource, password=password).addErrback( Failure.trap, error.ConnectionDone)
def enregister(svc, newAddress, password): """ Register a new account and return a Deferred that fires if it worked. @param svc: a Q2QService @param newAddress: a Q2QAddress object @param password: a shared secret (str) """ def trapit(x): x.trap(error.ConnectionDone) return svc.connectQ2Q( q2q.Q2QAddress("", ""), q2q.Q2QAddress(newAddress.domain, "accounts"), 'identity-admin', UserAdderFactory( newAddress.resource, password)).addCallback(lambda proto: proto.d).addErrback(trapit)
def test_stuff(self): svc = FakeQ2QService() serverAddr = q2q.Q2QAddress("domain", "accounts") server = AMP() def respond(box): self.assertEqual(box['_command'], "add_user") self.assertEqual(box['name'], "user") self.assertEqual(box['password'], "password") return AmpBox() server.amp_ADD_USER = respond factory = Factory.forProtocol(lambda: server) chooser = {"identity-admin": factory} svc.listenQ2Q(serverAddr, chooser, "Admin") d = q2qclient.enregister(svc, q2q.Q2QAddress("domain", "user"), "password") svc.flush() self.successResultOf(d)
def getQ2QPeer(self): from vertex import q2q return q2q.Q2QAddress('file.domain', 'peer.resource')
def _cbAuthorize(_): return svc.authorize(q2q.Q2QAddress(serverDomain, username), privateSecret).addCallback(lambda x: svc)