示例#1
0
    def test_get_domain_by_record_acl_email_fail(self):
        account = Account()
        account.email = "*****@*****.**"
        account.in_global_acl_emails = MagicMock(return_value=False)

        self.assertFalse(
            account.get_domain_by_record_acl(1, "example.com", "TXT"))
示例#2
0
    def test_get_domain_by_record_acl_domain_success(self):
        account = Account()
        account.email = "*****@*****.**"
        account.in_global_acl_emails = MagicMock(return_value=True)

        dm = MagicMock()
        dm.domain = "example.com"
        domain = MagicMock()
        domain.get = MagicMock(return_value=dm)
        account.get_domain_object = MagicMock(return_value=domain)

        account.get_global_acl_labels = MagicMock(return_value=["DOMAIN"])
        self.assertEquals(
            dm, account.get_domain_by_record_acl(1, "example.com", "TXT"))
示例#3
0
    def test_get_domain_by_record_acl_multiple_label_failure_two(self):
        account = Account()
        account.email = "*****@*****.**"
        account.in_global_acl_emails = MagicMock(return_value=True)

        dm = MagicMock()
        dm.domain = "example.com"
        domain = MagicMock()
        domain.get = MagicMock(return_value=dm)
        account.get_domain_object = MagicMock(return_value=domain)

        account.get_global_acl_labels = MagicMock(
            return_value=["_acme-challenge", "DOMAIN"])
        self.assertFalse(
            account.get_domain_by_record_acl(1, "foo.bar.example.com", "TXT"))
示例#4
0
    def mock_auth(email, password, active=True):
        h = "$2b$12$lqzxUnknwA/BYMJo2hFq5OBkkxsXP/7bupeNhizTFVa9WHaMOY6de"
        ph = "bcrypt||" + h

        account = Account()
        account.first_name = "Example"
        account.last_name = "User"
        account.email = '*****@*****.**'
        account.account_type = "senior_admin"
        account.password = ph
        if active is True:
            account.status = 'active'
        else:
            account.status = 'inactive'

        vegadns.api.common.Auth.get_account_by_email = MagicMock(
            return_value=account
        )
示例#5
0
    def test_get_domain_by_record_acl_multiple_label_success_no_match(self):
        account = Account()
        account.email = "*****@*****.**"
        account.in_global_acl_emails = MagicMock(return_value=True)

        dm = MagicMock()
        dm.domain = "example.com"
        dm.domain_id = 1
        dget = Mock()
        dget.side_effect = [dm, peewee.DoesNotExist, peewee.DoesNotExist]
        domain = MagicMock()
        domain.get = dget
        account.get_domain_object = MagicMock(return_value=domain)

        account.get_global_acl_labels = MagicMock(
            return_value=["_acme-challenge", "DOMAIN"])
        self.assertEquals(
            dm,
            account.get_domain_by_record_acl(
                1, "_acme-challenge.foo.bar.example.com", "TXT"))
示例#6
0
    def get_or_create_account_oidc(self, email, userinfo):
        try:
            return Account.get(
                Account.email == email,
                Account.status == 'active'
            )
        except peewee.DoesNotExist:
            pass
        oidc_conf = config['oidc']
        account = Account()
        account.email = email
        account.account_type = 'user'
        account.status = 'active'
        account.first_name = userinfo.get(oidc_conf.get('firstname_key'),'')
        account.last_name = userinfo.get(oidc_conf.get('lastname_key'),'')
        account.phone = userinfo.get(oidc_conf.get('phone_key'),'')
        # Save the new user to the DB
        account.save()

        return account
示例#7
0
    def test_status_validation(self):
        account = Account()

        account.first_name = "Test"
        account.last_name = "User"
        account.email = "*****@*****.**"
        account.account_type = "senior_admin"

        # good
        account.status = "active"
        self.assertIsNone(account.validate())

        # good
        account.status = "inactive"
        self.assertIsNone(account.validate())

        # bad
        account.status = "foobar"
        with self.assertRaises(Exception) as cm:
            account.validate()
        self.assertEquals('Invalid status: foobar', cm.exception.message)
示例#8
0
    def test_get_domain_by_record_acl_multiple_label_failure_collision(self):
        account = Account()
        account.email = "*****@*****.**"
        account.in_global_acl_emails = MagicMock(return_value=True)

        dm = MagicMock()
        dm.domain = "example.com"
        dm.domain_id = 1
        dm2 = MagicMock()
        dm2.domain = "bar.example.com"
        dm2.domain_id = 2

        dget = Mock()
        dget.side_effect = [dm, peewee.DoesNotExist, dm2]
        domain = Mock()
        domain.get = dget
        account.get_domain_object = MagicMock(return_value=domain)

        account.get_global_acl_labels = MagicMock(
            return_value=["_acme-challenge", "DOMAIN"])
        self.assertFalse(
            account.get_domain_by_record_acl(
                1, "_acme-challenge.foo.bar.example.com", "TXT"))
示例#9
0
 def test_get_domain_by_record_acl_fail_soa(self):
     account = Account()
     self.assertFalse(
         account.get_domain_by_record_acl(1, "example.com", "SOA"))
示例#10
0
    def test_get_domain(self):
        account = Account()

        self.assertEquals(peewee.BaseModel, type(account.get_domain_object()))