Пример #1
0
def get_full_dn_list():
    if request.method == 'GET':
        dn_list = DomainName.full_list()
        return dn_full_list_view(dn_list)

    elif request.method == 'POST':
        username = get_jwt_identity()
        dn_list = DomainName.list_recent_changes(username, 1, "", "domainName", "domainName", 25)

        alert_all(dn_list)
        return valid_view("alerts are being sent")
Пример #2
0
 def test_get(self):
     j = {
         "_key": domain_name,
         "records": [{
             "type": "A",
             "address": "address"
         }],
         "registrar": "registrar",
     }
     DomainName._get = MagicMock(return_value=j)
     d = DomainName.get(domain_name)
     self.assertEqual(d.domain_name, domain_name)
     self.assertEqual(d.records[0]['address'], "address")
Пример #3
0
def dn_retrieved_view(dn: DomainName, dn_tags: list, ip: IPAddress,
                      ip_tags: list, owned: bool, followed: bool):

    if ip is None:
        ip_json = None
    else:
        ip_json = ip.json()

    return jsonify({
        "msg": "domain name retrieved",
        "dn": dn.json(),
        "dn_tags": [t.tag for t in dn_tags],
        "ip": ip_json,
        "ip_tags": [t.tag for t in ip_tags],
        "owned": owned,
        "followed": followed
    }), 200
Пример #4
0
def get_list():
    try:
        username = get_jwt_identity()

        input_filter = request.args.get('filter')
        input_filter_by = request.args.get('filter_by')
        sort_by = request.args.get('sort_by')
        limit_str = request.args.get('limit')
        days_str = request.args.get('days')

        export = request.args.get('export')

        params = [input_filter, input_filter_by, sort_by, limit_str, days_str]
        for p in params:
            if p is None:
                return error_view(400, 'missing parameter')

        if not limit_str.isdigit():
            return error_view(400, 'invalid limit')

        if not days_str.isdigit():
            return error_view(400, 'invalid days count')

        limit = int(limit_str)
        days = int(days_str)

        t1 = time()
        dn_list = DomainName.list_recent_changes(
            username, days, input_filter, input_filter_by, sort_by, limit
        )
        t2 = time()
        transaction_time = round(t2 - t1, 2)

        if export is not None and export != '':
            return alert_list_export(dn_list, export)
        else:
            return alert_list(dn_list, transaction_time)

    except DomainNameFilterNotFound:
        return error_view(400, "invalid filter field")

    except DomainNameSortNotFound:
        return error_view(400, "invalid sort field")
Пример #5
0
def post(tag_name, object_key, object_type):
    if TagDnIP.exists(tag_name, object_key, object_type):
        return error_view(500, "tag link already exists")

    if not Tag.exists(tag_name):
        return error_view(404, "source tag not found")

    if object_type == DOMAIN_NAME_COLLECTION:
        object_exists = DomainName.exists(object_key)
    elif object_type == IP_ADDRESS_COLLECTION:
        object_exists = IPAddress.exists(object_key)
    else:
        return error_view(400, "invalid object type")

    if not object_exists:
        return error_view(404, "target object not found")

    new_tag_link = TagDnIP.new(tag_name, object_key, object_type)
    new_tag_link.insert()

    return tag_link_created_view(new_tag_link)
Пример #6
0
def dn_deleted_view(dn: DomainName):
    return jsonify({"msg": "domain name deleted", "dn": dn.json()}), 200
Пример #7
0
def dn_modified_view(dn: DomainName):
    return jsonify({"msg": "domain name modified", "dn": dn.json()}), 200
Пример #8
0
 def test_get_error(self):
     DomainName._get = MagicMock(side_effect=ObjectNotFound('not found'))
     with self.assertRaises(ObjectNotFound):
         DomainName.get("stuff")
Пример #9
0
 def test_exists_false(self):
     DomainName._exists = MagicMock(return_value=False)
     self.assertFalse(DomainName.exists(domain_name))
Пример #10
0
 def test_exists_true(self):
     DomainName._exists = MagicMock(return_value=True)
     self.assertTrue(DomainName.exists(domain_name))
Пример #11
0
 def test_resolve_exception(self):
     d = DomainName.new("stuff")
     ip = d.resolve()
     self.assertEqual(ip, None)
Пример #12
0
    def test_resolve(self):
        d = DomainName.new(domain_name)
        ip = d.resolve()

        expected_ip_address = "51.83.46.84"
        self.assertEqual(ip.address, expected_ip_address)
Пример #13
0
 def test_init(self):
     d = DomainName.new(domain_name)
     self.assertEqual(d.domain_name, domain_name)