Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1038)

Side by Side Diff: ppapi/tests/test_x509_certificate_private.cc

Issue 9699100: Add functionality to pppapi TCPSocket to support secure sockets in flash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_tcp_socket_private_trusted.cc ('k') | ppapi/thunk/interfaces_ppb_private.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/tests/test_x509_certificate_private.h" 5 #include "ppapi/tests/test_x509_certificate_private.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "ppapi/cpp/private/x509_certificate_private.h" 10 #include "ppapi/cpp/private/x509_certificate_private.h"
11 #include "ppapi/cpp/var_array_buffer.h" 11 #include "ppapi/cpp/var_array_buffer.h"
12 #include "ppapi/cpp/var.h" 12 #include "ppapi/cpp/var.h"
13 #include "ppapi/tests/testing_instance.h" 13 #include "ppapi/tests/testing_instance.h"
14 14
15 REGISTER_TEST_CASE(X509CertificatePrivate); 15 REGISTER_TEST_CASE(X509CertificatePrivate);
16 16
17 namespace { 17 namespace {
18 18
19 bool FieldMatchesString( 19 bool FieldMatchesString(
20 const pp::X509Certificate& certificate, 20 const pp::X509CertificatePrivate& certificate,
21 PP_X509Certificate_Private_Field field, 21 PP_X509Certificate_Private_Field field,
22 const std::string& expected) { 22 const std::string& expected) {
23 pp::Var field_value = certificate.GetField(field); 23 pp::Var field_value = certificate.GetField(field);
24 if (!field_value.is_string()) 24 if (!field_value.is_string())
25 return false; 25 return false;
26 return field_value.AsString() == expected; 26 return field_value.AsString() == expected;
27 } 27 }
28 28
29 bool FieldMatchesDouble( 29 bool FieldMatchesDouble(
30 const pp::X509Certificate& certificate, 30 const pp::X509CertificatePrivate& certificate,
31 PP_X509Certificate_Private_Field field, 31 PP_X509Certificate_Private_Field field,
32 double expected) { 32 double expected) {
33 pp::Var field_value = certificate.GetField(field); 33 pp::Var field_value = certificate.GetField(field);
34 if (!field_value.is_double()) 34 if (!field_value.is_double())
35 return false; 35 return false;
36 return std::fabs(field_value.AsDouble() - expected) <= 36 return std::fabs(field_value.AsDouble() - expected) <=
37 std::numeric_limits<double>::epsilon(); 37 std::numeric_limits<double>::epsilon();
38 } 38 }
39 39
40 bool FieldMatchesBuffer( 40 bool FieldMatchesBuffer(
41 const pp::X509Certificate& certificate, 41 const pp::X509CertificatePrivate& certificate,
42 PP_X509Certificate_Private_Field field, 42 PP_X509Certificate_Private_Field field,
43 const char* expected, 43 const char* expected,
44 uint32_t expected_length) { 44 uint32_t expected_length) {
45 pp::Var field_value = certificate.GetField(field); 45 pp::Var field_value = certificate.GetField(field);
46 if (!field_value.is_array_buffer()) 46 if (!field_value.is_array_buffer())
47 return false; 47 return false;
48 pp::VarArrayBuffer array_buffer(field_value); 48 pp::VarArrayBuffer array_buffer(field_value);
49 char* bytes = static_cast<char*>(array_buffer.Map()); 49 char* bytes = static_cast<char*>(array_buffer.Map());
50 uint32_t length = array_buffer.ByteLength(); 50 uint32_t length = array_buffer.ByteLength();
51 if (length != expected_length) 51 if (length != expected_length)
52 return false; 52 return false;
53 return std::equal(expected, expected + expected_length, bytes); 53 return std::equal(expected, expected + expected_length, bytes);
54 } 54 }
55 55
56 bool FieldIsNull( 56 bool FieldIsNull(
57 const pp::X509Certificate& certificate, 57 const pp::X509CertificatePrivate& certificate,
58 PP_X509Certificate_Private_Field field) { 58 PP_X509Certificate_Private_Field field) {
59 return certificate.GetField(field).is_null(); 59 return certificate.GetField(field).is_null();
60 } 60 }
61 61
62 // Google's cert. 62 // Google's cert.
63 const unsigned char kGoogleDer[] = { 63 const unsigned char kGoogleDer[] = {
64 0x30, 0x82, 0x03, 0x21, 0x30, 0x82, 0x02, 0x8a, 0xa0, 0x03, 0x02, 0x01, 64 0x30, 0x82, 0x03, 0x21, 0x30, 0x82, 0x02, 0x8a, 0xa0, 0x03, 0x02, 0x01,
65 0x02, 0x02, 0x10, 0x01, 0x2a, 0x39, 0x76, 0x0d, 0x3f, 0x4f, 0xc9, 0x0b, 65 0x02, 0x02, 0x10, 0x01, 0x2a, 0x39, 0x76, 0x0d, 0x3f, 0x4f, 0xc9, 0x0b,
66 0xe7, 0xbd, 0x2b, 0xcf, 0x95, 0x2e, 0x7a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 66 0xe7, 0xbd, 0x2b, 0xcf, 0x95, 0x2e, 0x7a, 0x30, 0x0d, 0x06, 0x09, 0x2a,
67 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x4c, 67 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x4c,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 }; 132 };
133 133
134 } // namespace 134 } // namespace
135 135
136 TestX509CertificatePrivate::TestX509CertificatePrivate( 136 TestX509CertificatePrivate::TestX509CertificatePrivate(
137 TestingInstance* instance) 137 TestingInstance* instance)
138 : TestCase(instance) { 138 : TestCase(instance) {
139 } 139 }
140 140
141 bool TestX509CertificatePrivate::Init() { 141 bool TestX509CertificatePrivate::Init() {
142 if (!pp::X509Certificate::IsAvailable()) 142 if (!pp::X509CertificatePrivate::IsAvailable())
143 return false; 143 return false;
144 144
145 return true; 145 return true;
146 } 146 }
147 147
148 void TestX509CertificatePrivate::RunTests(const std::string& filter) { 148 void TestX509CertificatePrivate::RunTests(const std::string& filter) {
149 RUN_TEST_FORCEASYNC_AND_NOT(ValidCertificate, filter); 149 RUN_TEST_FORCEASYNC_AND_NOT(ValidCertificate, filter);
150 RUN_TEST_FORCEASYNC_AND_NOT(InvalidCertificate, filter); 150 RUN_TEST_FORCEASYNC_AND_NOT(InvalidCertificate, filter);
151 } 151 }
152 152
153 std::string TestX509CertificatePrivate::TestValidCertificate() { 153 std::string TestX509CertificatePrivate::TestValidCertificate() {
154 pp::X509Certificate certificate(instance_); 154 pp::X509CertificatePrivate certificate(instance_);
155 bool successful = certificate.Initialize( 155 bool successful = certificate.Initialize(
156 reinterpret_cast<const char*>(kGoogleDer), sizeof(kGoogleDer)); 156 reinterpret_cast<const char*>(kGoogleDer), sizeof(kGoogleDer));
157 ASSERT_TRUE(successful); 157 ASSERT_TRUE(successful);
158 158
159 ASSERT_TRUE(FieldMatchesString(certificate, 159 ASSERT_TRUE(FieldMatchesString(certificate,
160 PP_X509CERTIFICATE_PRIVATE_SUBJECT_COMMON_NAME, "www.google.com")); 160 PP_X509CERTIFICATE_PRIVATE_SUBJECT_COMMON_NAME, "www.google.com"));
161 ASSERT_TRUE(FieldMatchesString(certificate, 161 ASSERT_TRUE(FieldMatchesString(certificate,
162 PP_X509CERTIFICATE_PRIVATE_SUBJECT_LOCALITY_NAME, "Mountain View")); 162 PP_X509CERTIFICATE_PRIVATE_SUBJECT_LOCALITY_NAME, "Mountain View"));
163 ASSERT_TRUE(FieldMatchesString(certificate, 163 ASSERT_TRUE(FieldMatchesString(certificate,
164 PP_X509CERTIFICATE_PRIVATE_SUBJECT_STATE_OR_PROVINCE_NAME, "California")); 164 PP_X509CERTIFICATE_PRIVATE_SUBJECT_STATE_OR_PROVINCE_NAME, "California"));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ASSERT_TRUE(FieldIsNull(certificate, 205 ASSERT_TRUE(FieldIsNull(certificate,
206 PP_X509CERTIFICATE_PRIVATE_ALGORITHM_PARAMATERS_RAW)); 206 PP_X509CERTIFICATE_PRIVATE_ALGORITHM_PARAMATERS_RAW));
207 ASSERT_TRUE(FieldIsNull(certificate, 207 ASSERT_TRUE(FieldIsNull(certificate,
208 PP_X509CERTIFICATE_PRIVATE_SUBJECT_PUBLIC_KEY)); 208 PP_X509CERTIFICATE_PRIVATE_SUBJECT_PUBLIC_KEY));
209 209
210 PASS(); 210 PASS();
211 } 211 }
212 212
213 std::string TestX509CertificatePrivate::TestInvalidCertificate() { 213 std::string TestX509CertificatePrivate::TestInvalidCertificate() {
214 bool successful; 214 bool successful;
215 pp::X509Certificate null_certificate(instance_); 215 pp::X509CertificatePrivate null_certificate(instance_);
216 successful = null_certificate.Initialize(NULL, 0); 216 successful = null_certificate.Initialize(NULL, 0);
217 ASSERT_FALSE(successful); 217 ASSERT_FALSE(successful);
218 218
219 pp::X509Certificate bad_certificate(instance_); 219 pp::X509CertificatePrivate bad_certificate(instance_);
220 successful = bad_certificate.Initialize("acbde", 0); 220 successful = bad_certificate.Initialize("acbde", 0);
221 ASSERT_FALSE(successful); 221 ASSERT_FALSE(successful);
222 222
223 PASS(); 223 PASS();
224 } 224 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_tcp_socket_private_trusted.cc ('k') | ppapi/thunk/interfaces_ppb_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698