Skip to content

Commit 83aaf8d

Browse files
committed
Added some very basic tests for Encryption and Decryption
1 parent e124a7a commit 83aaf8d

5 files changed

Lines changed: 11845 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#define CATCH_CONFIG_MAIN
2+
#include "catch.hpp"
3+
4+
#include <unordered_map>
5+
6+
#include "../UserPreferencesExplorer/Encryption.cpp"
7+
#include "../UserPreferencesExplorer/Utils.cpp"
8+
9+
TEST_CASE("UserPreferences") {
10+
const auto guid = std::string("01234567-89ab-cdef-0123-456789abcdef");
11+
const auto salt = std::string("6E3F032949637D2E");
12+
const auto plaintext = std::string("{\"username\":\"example@example.com\",\"refresh_token\":\"\",\"scope_string\":\"\"}");
13+
const auto ciphertext = std::vector<uint8_t>{
14+
0x80, 0x19, 0xD3, 0xEC, 0x72, 0x59, 0xA7, 0x5C, 0xC6, 0xDF, 0xF9, 0xBE,
15+
0x09, 0x51, 0xF8, 0x7C, 0x02, 0x7F, 0x4F, 0x63, 0x72, 0xCA, 0x02, 0xB0,
16+
0x32, 0xD5, 0x86, 0x6B, 0x68, 0x04, 0xC9, 0xD6, 0x7D, 0xFB, 0xBA, 0x39,
17+
0x11, 0x46, 0x1C, 0xF6, 0xE4, 0x94, 0xD3, 0xD8, 0xFD, 0xE2, 0x9B, 0x52,
18+
0x71, 0x89, 0xBB, 0x6C, 0x45, 0xF9, 0x87, 0x37, 0xF7, 0x4D, 0xCC, 0x15,
19+
0x17, 0xDC, 0x64, 0x6E, 0x72, 0x0F, 0x65, 0xB7, 0xC0, 0x65, 0x6F, 0xB9,
20+
0xBC, 0xB3, 0x04, 0x0D, 0xE5, 0x88, 0xAF, 0x5B
21+
};
22+
23+
SECTION("Encrypt")
24+
{
25+
auto data_to_encrypt = std::vector<uint8_t>(plaintext.begin(), plaintext.end());
26+
data_to_encrypt.push_back('\0');
27+
28+
auto result = Encryption::EncryptData(data_to_encrypt, guid, salt);
29+
30+
REQUIRE(result == ciphertext);
31+
}
32+
33+
SECTION("Decrypt")
34+
{
35+
auto result = Encryption::DecryptData(ciphertext, guid, salt);
36+
auto result_string = std::string(result.begin(), result.end() - 1);
37+
38+
REQUIRE(result_string == plaintext);
39+
}
40+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>15.0</VCProjectVersion>
23+
<ProjectGuid>{74BE1B66-A57A-44D1-9D92-05C1596BE7DA}</ProjectGuid>
24+
<Keyword>Win32Proj</Keyword>
25+
<RootNamespace>UserPreferencesExplorerTests</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v141</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v141</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v141</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v141</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
74+
<LinkIncremental>true</LinkIncremental>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
77+
<LinkIncremental>true</LinkIncremental>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
80+
<LinkIncremental>false</LinkIncremental>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
83+
<LinkIncremental>false</LinkIncremental>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
86+
<ClCompile>
87+
<PrecompiledHeader>
88+
</PrecompiledHeader>
89+
<WarningLevel>Level3</WarningLevel>
90+
<Optimization>Disabled</Optimization>
91+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
</ClCompile>
93+
<Link>
94+
<SubSystem>Console</SubSystem>
95+
</Link>
96+
</ItemDefinitionGroup>
97+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
98+
<ClCompile>
99+
<PrecompiledHeader>
100+
</PrecompiledHeader>
101+
<WarningLevel>Level3</WarningLevel>
102+
<Optimization>Disabled</Optimization>
103+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
104+
</ClCompile>
105+
<Link>
106+
<SubSystem>Console</SubSystem>
107+
</Link>
108+
</ItemDefinitionGroup>
109+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
110+
<ClCompile>
111+
<WarningLevel>Level3</WarningLevel>
112+
<PrecompiledHeader>
113+
</PrecompiledHeader>
114+
<Optimization>MaxSpeed</Optimization>
115+
<FunctionLevelLinking>true</FunctionLevelLinking>
116+
<IntrinsicFunctions>true</IntrinsicFunctions>
117+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118+
</ClCompile>
119+
<Link>
120+
<SubSystem>Console</SubSystem>
121+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
122+
<OptimizeReferences>true</OptimizeReferences>
123+
</Link>
124+
</ItemDefinitionGroup>
125+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
126+
<ClCompile>
127+
<WarningLevel>Level3</WarningLevel>
128+
<PrecompiledHeader>
129+
</PrecompiledHeader>
130+
<Optimization>MaxSpeed</Optimization>
131+
<FunctionLevelLinking>true</FunctionLevelLinking>
132+
<IntrinsicFunctions>true</IntrinsicFunctions>
133+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
134+
</ClCompile>
135+
<Link>
136+
<SubSystem>Console</SubSystem>
137+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
138+
<OptimizeReferences>true</OptimizeReferences>
139+
</Link>
140+
</ItemDefinitionGroup>
141+
<ItemGroup>
142+
<ClInclude Include="catch.hpp" />
143+
</ItemGroup>
144+
<ItemGroup>
145+
<ClCompile Include="Tests.cpp" />
146+
</ItemGroup>
147+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
148+
<ImportGroup Label="ExtensionTargets">
149+
</ImportGroup>
150+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="catch.hpp">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClCompile Include="Tests.cpp">
24+
<Filter>Source Files</Filter>
25+
</ClCompile>
26+
</ItemGroup>
27+
</Project>

0 commit comments

Comments
 (0)