Esempio n. 1
0
def test_base32():
    assert [base32_encode(x) for x in range(128)] == [
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
        'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z', '10', '11', '12',
        '13', '14', '15', '16', '17', '18', '19', '1A', '1B', '1C', '1D', '1E', '1F', '1G', '1H',
        '1J', '1K', '1M', '1N', '1P', '1Q', '1R', '1S', '1T', '1V', '1W', '1X', '1Y', '1Z', '20',
        '21', '22', '23', '24', '25', '26', '27', '28', '29', '2A', '2B', '2C', '2D', '2E', '2F',
        '2G', '2H', '2J', '2K', '2M', '2N', '2P', '2Q', '2R', '2S', '2T', '2V', '2W', '2X', '2Y',
        '2Z', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3A', '3B', '3C', '3D',
        '3E', '3F', '3G', '3H', '3J', '3K', '3M', '3N', '3P', '3Q', '3R', '3S', '3T', '3V', '3W',
        '3X', '3Y', '3Z'
    ]

    assert [base32_decode(base32_encode(x)) for x in range(128)] == list(map(int, range(128)))
Esempio n. 2
0
 def by_qualified_short_id(self, org, short_id):
     match = _short_id_re.match(short_id.strip())
     if match is None:
         raise Group.DoesNotExist()
     callsign, id = match.groups()
     callsign = callsign.upper()
     try:
         short_id = base32_decode(id)
     except ValueError:
         raise Group.DoesNotExist()
     return Group.objects.get(
         project__organization=org,
         project__callsign=callsign.upper(),
         short_id=short_id,
     )
Esempio n. 3
0
def parse_short_id(short_id):
    match = _short_id_re.match(short_id.strip())
    if match is None:
        return None
    slug, id = match.groups()
    slug = slug.lower()
    try:
        short_id = base32_decode(id)
        # We need to make sure the short id is not overflowing the
        # field's max or the lookup will fail with an assertion error.
        max_id = Group._meta.get_field_by_name('short_id')[0].MAX_VALUE
        if short_id > max_id:
            return None
    except ValueError:
        return None
    return ShortId(slug, short_id)
Esempio n. 4
0
def test_base32():
    assert [base32_encode(x) for x in range(128)] == [
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
        'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V',
        'W', 'X', 'Y', 'Z', '10', '11', '12', '13', '14', '15', '16', '17',
        '18', '19', '1A', '1B', '1C', '1D', '1E', '1F', '1G', '1H', '1J', '1K',
        '1M', '1N', '1P', '1Q', '1R', '1S', '1T', '1V', '1W', '1X', '1Y', '1Z',
        '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2A', '2B',
        '2C', '2D', '2E', '2F', '2G', '2H', '2J', '2K', '2M', '2N', '2P', '2Q',
        '2R', '2S', '2T', '2V', '2W', '2X', '2Y', '2Z', '30', '31', '32', '33',
        '34', '35', '36', '37', '38', '39', '3A', '3B', '3C', '3D', '3E', '3F',
        '3G', '3H', '3J', '3K', '3M', '3N', '3P', '3Q', '3R', '3S', '3T', '3V',
        '3W', '3X', '3Y', '3Z'
    ]

    assert [base32_decode(base32_encode(x))
            for x in range(128)] == list(map(int, range(128)))
Esempio n. 5
0
 def by_qualified_short_id(self, org, short_id):
     match = _short_id_re.match(short_id.strip())
     if match is None:
         raise Group.DoesNotExist()
     callsign, id = match.groups()
     callsign = callsign.lower()
     try:
         short_id = base32_decode(id)
         # We need to make sure the short id is not overflowing the
         # field's max or the lookup will fail with an assertion error.
         max_id = Group._meta.get_field_by_name('short_id')[0].MAX_VALUE
         if short_id > max_id:
             raise ValueError()
     except ValueError:
         raise Group.DoesNotExist()
     return Group.objects.get(
         project__organization=org,
         project__slug=callsign,
         short_id=short_id,
     )
 def by_qualified_short_id(self, organization_id, short_id):
     match = _short_id_re.match(short_id.strip())
     if match is None:
         raise Group.DoesNotExist()
     slug, id = match.groups()
     slug = slug.lower()
     try:
         short_id = base32_decode(id)
         # We need to make sure the short id is not overflowing the
         # field's max or the lookup will fail with an assertion error.
         max_id = Group._meta.get_field_by_name('short_id')[0].MAX_VALUE
         if short_id > max_id:
             raise ValueError()
     except ValueError:
         raise Group.DoesNotExist()
     return Group.objects.get(
         project__organization=organization_id,
         project__slug=slug,
         short_id=short_id,
     )
Esempio n. 7
0
def process_signature(request, max_age=60 * 60 * 24 * 2):
    """Given a request object this validates the signature from the
    current request and returns the user.
    """
    sig = request.GET.get('_') or request.POST.get('_sentry_request_signature')
    if not sig or sig.count(':') < 2:
        return None

    signed_data = '%s|%s|%s' % (request.build_absolute_uri('/').rstrip('/'),
                                request.path, sig)
    try:
        data = get_signer().unsign(signed_data, max_age=max_age)
    except signing.BadSignature:
        return None

    _, signed_path, user_id = data.rsplit('|', 2)
    if signed_path != request.path:
        return None

    try:
        return User.objects.get(pk=base32_decode(user_id))
    except (ValueError, User.DoesNotExist):
        return None
Esempio n. 8
0
def test_base32():
    assert [base32_encode(x) for x in range(128)] == [
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "J",
        "K",
        "M",
        "N",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "V",
        "W",
        "X",
        "Y",
        "Z",
        "10",
        "11",
        "12",
        "13",
        "14",
        "15",
        "16",
        "17",
        "18",
        "19",
        "1A",
        "1B",
        "1C",
        "1D",
        "1E",
        "1F",
        "1G",
        "1H",
        "1J",
        "1K",
        "1M",
        "1N",
        "1P",
        "1Q",
        "1R",
        "1S",
        "1T",
        "1V",
        "1W",
        "1X",
        "1Y",
        "1Z",
        "20",
        "21",
        "22",
        "23",
        "24",
        "25",
        "26",
        "27",
        "28",
        "29",
        "2A",
        "2B",
        "2C",
        "2D",
        "2E",
        "2F",
        "2G",
        "2H",
        "2J",
        "2K",
        "2M",
        "2N",
        "2P",
        "2Q",
        "2R",
        "2S",
        "2T",
        "2V",
        "2W",
        "2X",
        "2Y",
        "2Z",
        "30",
        "31",
        "32",
        "33",
        "34",
        "35",
        "36",
        "37",
        "38",
        "39",
        "3A",
        "3B",
        "3C",
        "3D",
        "3E",
        "3F",
        "3G",
        "3H",
        "3J",
        "3K",
        "3M",
        "3N",
        "3P",
        "3Q",
        "3R",
        "3S",
        "3T",
        "3V",
        "3W",
        "3X",
        "3Y",
        "3Z",
    ]

    assert [base32_decode(base32_encode(x))
            for x in range(128)] == list(range(128))
Esempio n. 9
0
def test_base32():
    assert [base32_encode(x) for x in xrange(128)] == [
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "J",
        "K",
        "M",
        "N",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "V",
        "W",
        "X",
        "Y",
        "Z",
        "10",
        "11",
        "12",
        "13",
        "14",
        "15",
        "16",
        "17",
        "18",
        "19",
        "1A",
        "1B",
        "1C",
        "1D",
        "1E",
        "1F",
        "1G",
        "1H",
        "1J",
        "1K",
        "1M",
        "1N",
        "1P",
        "1Q",
        "1R",
        "1S",
        "1T",
        "1V",
        "1W",
        "1X",
        "1Y",
        "1Z",
        "20",
        "21",
        "22",
        "23",
        "24",
        "25",
        "26",
        "27",
        "28",
        "29",
        "2A",
        "2B",
        "2C",
        "2D",
        "2E",
        "2F",
        "2G",
        "2H",
        "2J",
        "2K",
        "2M",
        "2N",
        "2P",
        "2Q",
        "2R",
        "2S",
        "2T",
        "2V",
        "2W",
        "2X",
        "2Y",
        "2Z",
        "30",
        "31",
        "32",
        "33",
        "34",
        "35",
        "36",
        "37",
        "38",
        "39",
        "3A",
        "3B",
        "3C",
        "3D",
        "3E",
        "3F",
        "3G",
        "3H",
        "3J",
        "3K",
        "3M",
        "3N",
        "3P",
        "3Q",
        "3R",
        "3S",
        "3T",
        "3V",
        "3W",
        "3X",
        "3Y",
        "3Z",
    ]

    assert [base32_decode(base32_encode(x)) for x in xrange(128)] == range(128)