Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Uplay Key Analyzer with tests
- Loading branch information
Showing
3 changed files
with
61 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,45 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.uplaykeyanalyzer import UplayKeyAnalyzer | ||
|
||
|
||
class TestUplayKeyAnalyzer(unittest.TestCase): | ||
def setUp(self): | ||
self.analyzer = UplayKeyAnalyzer(None) | ||
self.paste = mock.Mock() | ||
|
||
def test_match_positive(self): | ||
"""Test if positives are recognized""" | ||
# steam key dump | ||
self.paste.body = "MB9C-LV3C-4RG8-FME8" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# part of a sentence | ||
self.paste.body = "Hey, I have your key right here: MB9C-LV3C-4RG8-FME8!" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# Newline seperated steam key | ||
self.paste.body = "MB9C-LV3C-4RG8-FME8\nMB9C-LV3C-4RG8-FME8" | ||
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 = "MB9AC-LV3C-4RG8-FME8" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Lower-case | ||
self.paste.body = "mb9c-lv3c-4rg8-fme8" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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 UplayKeyAnalyzer(RegexAnalyzer): | ||
""" | ||
Analyzer to match uplay keys via regex | ||
""" | ||
name = "UplayKeyAnalyzer" | ||
|
||
def __init__(self, actions): | ||
regex = r"\b[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\b" | ||
super().__init__(actions, regex) |