Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add unix timestamp support #85

Merged
merged 10 commits into from
Jul 2, 2021
44 changes: 44 additions & 0 deletions pywhat/Data/regex.json
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,28 @@
"Phone Number"
]
},
{
"Name": "Recent Unix Timestamp",
"Regex": "^[0-9]{10}$",
"plural_name": false,
"Description": "Seconds elapsed since unix epoch: 1970, between year 2001 and 2286",
"Rarity": 0.5,
"URL": null,
"Tags": [
"Time"
]
},
{
"Name": "Recent Unix Millisecond Timestamp",
"Regex": "^[0-9]{13}$",
"plural_name": false,
"Description": "Milliseconds elapsed since unix epoch: 1970, between year 2001 and 2286",
"Rarity": 0.5,
"URL": null,
"Tags": [
"Time"
]
},
{
"Name": "YouTube Channel ID",
"Regex": "^UC[0-9A-Za-z_-]{21}[AQgw]{1}$",
Expand Down Expand Up @@ -716,6 +738,28 @@
"SSN"
]
},
{
"Name": "Unix Timestamp",
"Regex": "^[0-9]{8,10}$",
"plural_name": false,
"Description": "Seconds elapsed since unix epoch: 1970",
"Rarity": 0.2,
"URL": null,
"Tags": [
"Time"
]
},
{
"Name": "Unix Millisecond Timestamp",
"Regex": "^[0-9]{11,13}$",
"plural_name": false,
"Description": "Milliseconds elapsed since unix epoch: 1970",
"Rarity": 0.2,
"URL": null,
"Tags": [
"Time"
]
},
{
"Name": "Key:Value Pair",
"Regex": "[^:\\s]+[ ]?:[ ]?[^:\\s]+",
Expand Down
44 changes: 44 additions & 0 deletions tests/test_regex_identifier.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from datetime import datetime
from time import time

import pytest

from pywhat import regex_identifier
Expand Down Expand Up @@ -475,6 +478,47 @@ def test_arn4():
res = r.check(["arn:aws:s3:::my_corporate_bucket/Development/*"])
assert "ARN" in str(res)


def test_unix_timestamp1():
r = regex_identifier.RegexIdentifier()
res = r.check(["1577836800"]) # 2020-01-01
keys = [m['Regex Pattern']['Name'] for m in res]
assert "Unix Timestamp" in keys
assert "Recent Unix Timestamp" in keys


def test_unix_timestamp2():
r = regex_identifier.RegexIdentifier()
res = r.check(["94694400"]) # 1973-01-01
keys = [m['Regex Pattern']['Name'] for m in res]
assert "Unix Timestamp" in keys
assert "Recent Unix Timestamp" not in keys


def test_unix_timestamp3():
r = regex_identifier.RegexIdentifier()
res = r.check(["1234567"]) # 7 numbers
keys = [m['Regex Pattern']['Name'] for m in res]
assert "Unix Timestamp" not in keys
assert "Recent Unix Timestamp" not in keys


def test_unix_timestamp4():
r = regex_identifier.RegexIdentifier()
res = r.check(["1577836800000"]) # 2020-01-01
keys = [m['Regex Pattern']['Name'] for m in res]
assert "Unix Millisecond Timestamp" in keys
assert "Recent Unix Millisecond Timestamp" in keys


def test_unix_timestamp5():
r = regex_identifier.RegexIdentifier()
res = r.check(["94694400000"]) # 1973-01-01
keys = [m['Regex Pattern']['Name'] for m in res]
assert "Unix Millisecond Timestamp" in keys
assert "Recent Unix Millisecond Timestamp" not in keys


def test_ssh_rsa_key():
r = regex_identifier.RegexIdentifier()
res = r.check(
Expand Down