-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from mikek2/steam-keys
Added steam key analyzer fixes #96
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
from .regexanalyzer import RegexAnalyzer | ||
|
||
|
||
class SteamKeyAnalyzer(RegexAnalyzer): | ||
""" | ||
Analyzer to match steam keys via regex | ||
""" | ||
name = "SteamKeyAnalyzer" | ||
|
||
def __init__(self, actions): | ||
regex = r"\b[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}\b" | ||
super().__init__(actions, regex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.steamkeyanalyzer import SteamKeyAnalyzer | ||
|
||
|
||
class TestSteamKeyAnalyzer(unittest.TestCase): | ||
def setUp(self): | ||
self.analyzer = SteamKeyAnalyzer(None) | ||
self.paste = mock.Mock() | ||
|
||
def test_match_positive(self): | ||
"""Test if positives are recognized""" | ||
# steam key dump | ||
self.paste.body = "EZFNY-7GECB-94WRD" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# steam key dump | ||
self.paste.body = "10NL7-7E8VK-ZUSOD" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# steam key dump | ||
self.paste.body = "CB6AW-XHHB1-IANNO" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# steam key dump | ||
self.paste.body = "E4XJ8-2MRI0-RX4I5" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# part of a sentence | ||
self.paste.body = "Hey, I have your key right here: EL0SY-DC710-X0C5W!" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# Newline seperated steam key | ||
self.paste.body = "E4XJ8-2MRI0-RX4I5\nCIZ36-WD38P-QZI6U" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
def test_match_negative(self): | ||
"""Test if negatives are not recognized""" | ||
self.paste.body = "" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
self.paste.body = None | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Invalid length | ||
self.paste.body = "CBCB6AW-XHHB1-IANNO" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Lower-case | ||
self.paste.body = "e4xj8-2mri0-rx4i5" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |