OLD | NEW |
| (Empty) |
1 // Copyright 2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // Unit tests for the Google file signature validation. | |
17 | |
18 #include <windows.h> | |
19 #include <atlstr.h> | |
20 #include "omaha/base/app_util.h" | |
21 #include "omaha/base/file.h" | |
22 #include "omaha/base/signaturevalidator.h" | |
23 #include "omaha/testing/unit_test.h" | |
24 | |
25 namespace omaha { | |
26 | |
27 class SignatureValidatorTest : public testing::Test { | |
28 virtual void SetUp() { | |
29 } | |
30 | |
31 virtual void TearDown() { | |
32 } | |
33 }; | |
34 | |
35 | |
36 TEST_F(SignatureValidatorTest, VerifySigneeIsGoogle_OfficiallySigned) { | |
37 const TCHAR kRelativePath[] = _T("unittest_support\\SaveArguments.exe"); | |
38 | |
39 CString executable_full_path(app_util::GetCurrentModuleDirectory()); | |
40 ASSERT_TRUE(::PathAppend(CStrBuf(executable_full_path, MAX_PATH), | |
41 kRelativePath)); | |
42 ASSERT_TRUE(File::Exists(executable_full_path)); | |
43 EXPECT_TRUE(VerifySigneeIsGoogle(executable_full_path)); | |
44 } | |
45 | |
46 // Tests a certificate subject containing multiple CNs such as: | |
47 // "CN = Google Inc (TEST), CN = Some Other CN, ... | |
48 // The code exactly matches on the first CN only. | |
49 TEST_F(SignatureValidatorTest, VerifySigneeIsGoogle_TestSigned_MultipleCN) { | |
50 const TCHAR kRelativePath[] = | |
51 _T("unittest_support\\SaveArguments_multiple_cn.exe"); | |
52 | |
53 CString executable_full_path(app_util::GetCurrentModuleDirectory()); | |
54 ASSERT_TRUE(::PathAppend(CStrBuf(executable_full_path, MAX_PATH), | |
55 kRelativePath)); | |
56 ASSERT_TRUE(File::Exists(executable_full_path)); | |
57 EXPECT_TRUE(VerifySigneeIsGoogle(executable_full_path)); | |
58 } | |
59 | |
60 TEST_F(SignatureValidatorTest, | |
61 VerifySigneeIsGoogle_OfficiallySigned_DifferentOU) { | |
62 const TCHAR kRelativePath[] = | |
63 _T("unittest_support\\SaveArguments_different_ou.exe"); | |
64 | |
65 CString executable_full_path(app_util::GetCurrentModuleDirectory()); | |
66 ASSERT_TRUE(::PathAppend(CStrBuf(executable_full_path, MAX_PATH), | |
67 kRelativePath)); | |
68 ASSERT_TRUE(File::Exists(executable_full_path)); | |
69 EXPECT_TRUE(VerifySigneeIsGoogle(executable_full_path)); | |
70 } | |
71 | |
72 TEST_F(SignatureValidatorTest, VerifySigneeIsGoogle_OmahaTestSigned) { | |
73 const TCHAR kRelativePath[] = | |
74 _T("unittest_support\\SaveArguments_OmahaTestSigned.exe"); | |
75 | |
76 CString executable_full_path(app_util::GetCurrentModuleDirectory()); | |
77 ASSERT_TRUE(::PathAppend(CStrBuf(executable_full_path, MAX_PATH), | |
78 kRelativePath)); | |
79 ASSERT_TRUE(File::Exists(executable_full_path)); | |
80 EXPECT_TRUE(VerifySigneeIsGoogle(executable_full_path)); | |
81 } | |
82 | |
83 // The certificate was valid when it was used to sign the executable, but it has | |
84 // since expired. | |
85 TEST_F(SignatureValidatorTest, VerifySigneeIsGoogle_SignedWithNowExpiredCert) { | |
86 const TCHAR kRelativePath[] = | |
87 _T("unittest_support\\GoogleUpdate_now_expired_cert.exe"); | |
88 | |
89 CString executable_full_path(app_util::GetCurrentModuleDirectory()); | |
90 ASSERT_TRUE(::PathAppend(CStrBuf(executable_full_path, MAX_PATH), | |
91 kRelativePath)); | |
92 ASSERT_TRUE(File::Exists(executable_full_path)); | |
93 EXPECT_TRUE(VerifySigneeIsGoogle(executable_full_path)); | |
94 } | |
95 | |
96 TEST_F(SignatureValidatorTest, VerifySigneeIsGoogle_TestSigned_NoCN) { | |
97 const TCHAR kRelativePath[] = | |
98 _T("unittest_support\\SaveArguments_no_cn.exe"); | |
99 | |
100 CString executable_full_path(app_util::GetCurrentModuleDirectory()); | |
101 ASSERT_TRUE(::PathAppend(CStrBuf(executable_full_path, MAX_PATH), | |
102 kRelativePath)); | |
103 ASSERT_TRUE(File::Exists(executable_full_path)); | |
104 EXPECT_FALSE(VerifySigneeIsGoogle(executable_full_path)); | |
105 } | |
106 | |
107 TEST_F(SignatureValidatorTest, VerifySigneeIsGoogle_TestSigned_WrongCN) { | |
108 const TCHAR kRelativePath[] = | |
109 _T("unittest_support\\SaveArguments_wrong_cn.exe"); | |
110 | |
111 CString executable_full_path(app_util::GetCurrentModuleDirectory()); | |
112 ASSERT_TRUE(::PathAppend(CStrBuf(executable_full_path, MAX_PATH), | |
113 kRelativePath)); | |
114 ASSERT_TRUE(File::Exists(executable_full_path)); | |
115 EXPECT_FALSE(VerifySigneeIsGoogle(executable_full_path)); | |
116 } | |
117 | |
118 } // namespace omaha | |
OLD | NEW |