Esempio n. 1
0
    def setUp(self):
        config = {
            "general": {
                "ip.blacklist": "5.0.0.0/8",
                "ip.whitelist": "5.1.1.1",
            },
        }

        self.sydent = make_sydent(test_config=config)

        self.reactor = self.sydent.reactor

        self.safe_domain, self.safe_ip = b"safe.test", b"1.2.3.4"
        self.unsafe_domain, self.unsafe_ip = b"danger.test", b"5.6.7.8"
        self.allowed_domain, self.allowed_ip = b"allowed.test", b"5.1.1.1"

        # Configure the reactor's DNS resolver.
        for (domain, ip) in (
            (self.safe_domain, self.safe_ip),
            (self.unsafe_domain, self.unsafe_ip),
            (self.allowed_domain, self.allowed_ip),
        ):
            self.reactor.lookups[domain.decode()] = ip.decode()
            self.reactor.lookups[ip.decode()] = ip.decode()

        self.ip_whitelist = self.sydent.config.general.ip_whitelist
        self.ip_blacklist = self.sydent.config.general.ip_blacklist
Esempio n. 2
0
    def setUp(self):
        # Create a new sydent
        self.sydent = make_sydent()

        # Create a fake peer to replicate to.
        peer_public_key_base64 = "+vB8mTaooD/MA8YYZM8t9+vnGhP1937q2icrqPV9JTs"

        # Inject our fake peer into the database.
        cur = self.sydent.db.cursor()
        cur.execute(
            "INSERT INTO peers (name, port, lastSentVersion, active) VALUES (?, ?, ?, ?)",
            ("fake.server", 1234, 0, 1),
        )
        cur.execute(
            "INSERT INTO peer_pubkeys (peername, alg, key) VALUES (?, ?, ?)",
            ("fake.server", "ed25519", peer_public_key_base64),
        )

        self.sydent.db.commit()

        # Build some fake associations.
        self.assocs = []
        assoc_count = 150
        for i in range(assoc_count):
            assoc = ThreepidAssociation(
                medium="email",
                address="*****@*****.**" % i,
                lookup_hash=None,
                mxid="@bob%d:example.com" % i,
                ts=(i * 10000),
                not_before=0,
                not_after=99999999999,
            )
            self.assocs.append(assoc)
Esempio n. 3
0
 def setUp(self):
     # Create a new sydent
     config = {
         "general": {
             "delete_tokens_on_bind": "false"
         }
     }
     self.sydent = make_sydent(test_config=config)
Esempio n. 4
0
 def setUp(self) -> None:
     # Create a new sydent
     config = {
         "email": {
             "email.from": "Sydent Validation <noreply@hostname>",
         },
     }
     self.sydent = make_sydent(test_config=config)
     self.sender = "@alice:wonderland"
Esempio n. 5
0
 def setUp(self):
     # Create a new sydent
     config = {
         "general": {
             "templates.path":
             os.path.join(os.path.dirname(os.path.dirname(__file__)),
                          "res"),
         },
     }
     self.sydent = make_sydent(test_config=config)
Esempio n. 6
0
 def setUp(self):
     # Create a new sydent
     config = {
         "email": {
             # Used by test_invited_email_address_obfuscation
             "email.third_party_invite_username_obfuscate_characters": "6",
             "email.third_party_invite_domain_obfuscate_characters": "8",
         },
     }
     self.sydent = make_sydent(test_config=config)
Esempio n. 7
0
    def test_incoming_replication(self):
        """Impersonate a peer that sends a replication push to Sydent, then checks that it
        accepts the payload and saves it correctly.
        """
        self.sydent.run()

        # Configure the Sydent to impersonate. We need to use "fake.server" as the
        # server's name because that's the name the recipient Sydent has for it. On top
        # of that, the replication servlet expects a TLS certificate in the request so it
        # can extract a common name and figure out which peer sent it from its common
        # name. The common name of the certificate we use for tests is fake.server.
        config = {
            "general": {
                "server.name": "fake.server"
            },
            "crypto": {
                "ed25519.signingkey":
                "ed25519 0 b29eXMMAYCFvFEtq9mLI42aivMtcg4Hl0wK89a+Vb6c"
            },
        }

        fake_sender_sydent = make_sydent(config)
        signer = Signer(fake_sender_sydent)

        # Sign the associations with the Sydent to impersonate so the recipient Sydent
        # can verify the signatures on them.
        signed_assocs = {}
        for assoc_id, assoc in enumerate(self.assocs):
            signed_assoc = signer.signedThreePidAssociation(assoc)
            signed_assocs[assoc_id] = signed_assoc

        # Send the replication push.
        body = json.dumps({"sgAssocs": signed_assocs})
        request, channel = make_request(self.sydent.reactor, "POST",
                                        "/_matrix/identity/replicate/v1/push",
                                        body)
        request.render(self.sydent.servlets.replicationPush)

        self.assertEqual(channel.code, 200)

        # Check that the recipient Sydent has correctly saved the associations in the
        # push.
        cur = self.sydent.db.cursor()
        res = cur.execute(
            "SELECT originId, sgAssoc FROM global_threepid_associations")

        res_assocs = {}
        for row in res.fetchall():
            originId = row[0]
            signed_assoc = json.loads(row[1])

            res_assocs[originId] = signed_assoc

        for assoc_id, signed_assoc in signed_assocs.items():
            self.assertDictEqual(signed_assoc, res_assocs[assoc_id])
Esempio n. 8
0
    def setUp(self):
        # Create a new sydent
        self.sydent = make_sydent()
        self.test_token = "testingtoken"

        # Inject a fake OpenID token into the database
        cur = self.sydent.db.cursor()
        cur.execute(
            "INSERT INTO accounts (user_id, created_ts, consent_version)"
            "VALUES (?, ?, ?)", ("@bob:localhost", 101010101, "asd"))
        cur.execute("INSERT INTO tokens (user_id, token)"
                    "VALUES (?, ?)", ("@bob:localhost", self.test_token))

        self.sydent.db.commit()
Esempio n. 9
0
 def setUp(self) -> None:
     # Create a new sydent
     config = {
         "general": {
             "templates.path": os.path.join(
                 os.path.dirname(os.path.dirname(__file__)), "res"
             ),
         },
         "email": {
             "email.from": "Sydent Validation <noreply@hostname>",
         },
     }
     self.sydent = make_sydent(test_config=config)
     self.sender = "@alice:wonderland"
Esempio n. 10
0
 def test_start(self):
     sydent = make_sydent()
     sydent.run()
Esempio n. 11
0
 def setUp(self):
     # Create a new sydent
     self.sydent = make_sydent()
Esempio n. 12
0
    def setUp(self):
        # Create a new sydent
        config = {
            "general": {
                "templates.path":
                os.path.join(os.path.dirname(os.path.dirname(__file__)),
                             "res"),
            },
            "crypto": {
                "ed25519.signingkey":
                "ed25519 0 FJi1Rnpj3/otydngacrwddFvwz/dTDsBv62uZDN2fZM"
            },
        }
        self.sydent = make_sydent(test_config=config)

        # create some local associations
        associations = []

        for i in range(10):
            address = "*****@*****.**" % i
            associations.append({
                "medium":
                "email",
                "address":
                address,
                "lookup_hash":
                calculate_lookup_hash(self.sydent, address),
                "mxid":
                "@bob%d:example.com" % i,
                "ts": (i * 10000),
                "not_before":
                0,
                "not_after":
                99999999999,
            })
        # create some casefold-conflicting associations
        for i in range(5):
            address = "*****@*****.**" % i
            associations.append({
                "medium":
                "email",
                "address":
                address,
                "lookup_hash":
                calculate_lookup_hash(self.sydent, address),
                "mxid":
                "@otherbob%d:example.com" % i,
                "ts": (i * 10000),
                "not_before":
                0,
                "not_after":
                99999999999,
            })

        # add all associations to db
        cur = self.sydent.db.cursor()

        cur.executemany(
            "INSERT INTO  local_threepid_associations "
            "(medium, address, lookup_hash, mxid, ts, notBefore, notAfter) "
            "VALUES (?, ?, ?, ?, ?, ?, ?)",
            [(
                assoc["medium"],
                assoc["address"],
                assoc["lookup_hash"],
                assoc["mxid"],
                assoc["ts"],
                assoc["not_before"],
                assoc["not_after"],
            ) for assoc in associations],
        )

        self.sydent.db.commit()

        # create some global associations
        associations = []
        originServer = self.sydent.config.general.server_name

        for i in range(10):
            address = "*****@*****.**" % i
            mxid = "@bob%d:example.com" % i
            ts = 10000 * i
            associations.append({
                "medium":
                "email",
                "address":
                address,
                "lookup_hash":
                calculate_lookup_hash(self.sydent, address),
                "mxid":
                mxid,
                "ts":
                ts,
                "not_before":
                0,
                "not_after":
                99999999999,
                "originServer":
                originServer,
                "originId":
                i,
                "sgAssoc":
                json.dumps(
                    self.create_signedassoc("email", address, mxid, ts, 0,
                                            99999999999)),
            })
        # create some casefold-conflicting associations
        for i in range(5):
            address = "*****@*****.**" % i
            mxid = "@BOB%d:example.com" % i
            ts = 10000 * i
            associations.append({
                "medium":
                "email",
                "address":
                address,
                "lookup_hash":
                calculate_lookup_hash(self.sydent, address),
                "mxid":
                mxid,
                "ts":
                ts + 1,
                "not_before":
                0,
                "not_after":
                99999999999,
                "originServer":
                originServer,
                "originId":
                i + 10,
                "sgAssoc":
                json.dumps(
                    self.create_signedassoc("email", address, mxid, ts, 0,
                                            99999999999)),
            })

        # add all associations to db
        cur = self.sydent.db.cursor()

        cur.executemany(
            "INSERT INTO global_threepid_associations "
            "(medium, address, lookup_hash, mxid, ts, notBefore, notAfter, originServer, originId, sgAssoc) "
            "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
            [(
                assoc["medium"],
                assoc["address"],
                assoc["lookup_hash"],
                assoc["mxid"],
                assoc["ts"],
                assoc["not_before"],
                assoc["not_after"],
                assoc["originServer"],
                assoc["originId"],
                assoc["sgAssoc"],
            ) for assoc in associations],
        )

        self.sydent.db.commit()