Add certificate_provisioning_unittest
[ Merge of http://go/wvgerrit/87964 ] A preliminary test has been added, more to follow. Bug: 142747616 Test: android unit tests Change-Id: Ida8eb853c14f73f60f7bc354f14a02224c2ce66c
This commit is contained in:
@@ -35,6 +35,7 @@ WV_TEST_TARGETS="base64_test \
|
|||||||
cdm_feature_test \
|
cdm_feature_test \
|
||||||
cdm_extended_duration_test \
|
cdm_extended_duration_test \
|
||||||
cdm_session_unittest \
|
cdm_session_unittest \
|
||||||
|
certificate_provisioning_unittest \
|
||||||
counter_metric_unittest \
|
counter_metric_unittest \
|
||||||
crypto_session_unittest \
|
crypto_session_unittest \
|
||||||
device_files_unittest \
|
device_files_unittest \
|
||||||
|
|||||||
@@ -249,7 +249,10 @@ class CryptoSession {
|
|||||||
private:
|
private:
|
||||||
friend class CryptoSessionForTest;
|
friend class CryptoSessionForTest;
|
||||||
friend class CryptoSessionFactory;
|
friend class CryptoSessionFactory;
|
||||||
|
#if defined(UNIT_TEST)
|
||||||
|
friend class CertificateProvisioningTest;
|
||||||
friend class WvCdmTestBase;
|
friend class WvCdmTestBase;
|
||||||
|
#endif
|
||||||
|
|
||||||
// The global factory method can be set to generate special crypto sessions
|
// The global factory method can be set to generate special crypto sessions
|
||||||
// just for testing. These sessions will avoid nonce floods and will ask
|
// just for testing. These sessions will avoid nonce floods and will ask
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
// Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||||
|
// source code may only be used and distributed under the Widevine Master
|
||||||
|
// License Agreement.
|
||||||
|
|
||||||
|
#include "certificate_provisioning.h"
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "crypto_session.h"
|
||||||
|
#include "metrics_collections.h"
|
||||||
|
#include "test_base.h"
|
||||||
|
#include "wv_cdm_types.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const std::string kSignedDeviceCertificate = wvcdm::a2bs_hex(
|
||||||
|
"0A350802121B7769646576696E655F746573745F73657269616C5F6E756D62657228D2093A"
|
||||||
|
"11746573742E7769646576696E652E636F6D12097369676E6174757265");
|
||||||
|
const std::string kSignedDeviceCertificateInvalid = wvcdm::a2bs_hex(
|
||||||
|
"76340802121B7769646576696E655F746573745F73657269616C5F6E756D62657228D2093A"
|
||||||
|
"11746573742E7769646576696E652E636F6D12097369676E6174757265");
|
||||||
|
const std::string kSignedDeviceCertificateNoDrmCertificate =
|
||||||
|
wvcdm::a2bs_hex("12097369676E6174757265");
|
||||||
|
const std::string kSignedDeviceCertificateInvalidCertificateType =
|
||||||
|
wvcdm::a2bs_hex(
|
||||||
|
"0A350801121B7769646576696E655F746573745F73657269616C5F6E756D62657228D2"
|
||||||
|
"093A11746573742E7769646576696E652E636F6D12097369676E6174757265");
|
||||||
|
const std::string kSerialNumber = "widevine_test_serial_number";
|
||||||
|
const uint32_t kSystemId = 1234;
|
||||||
|
|
||||||
|
} // unnamed namespace
|
||||||
|
|
||||||
|
namespace wvcdm {
|
||||||
|
|
||||||
|
class MockCryptoSession : public TestCryptoSession {
|
||||||
|
public:
|
||||||
|
MockCryptoSession(metrics::CryptoMetrics* metrics)
|
||||||
|
: TestCryptoSession(metrics) {}
|
||||||
|
MOCK_METHOD1(Open, CdmResponseType(SecurityLevel));
|
||||||
|
MOCK_METHOD1(LoadUsageTableHeader,
|
||||||
|
CdmResponseType(const CdmUsageTableHeader&));
|
||||||
|
MOCK_METHOD1(CreateUsageTableHeader, CdmResponseType(CdmUsageTableHeader*));
|
||||||
|
MOCK_METHOD1(CreateUsageEntry, CdmResponseType(uint32_t*));
|
||||||
|
MOCK_METHOD2(LoadUsageEntry, CdmResponseType(uint32_t, const CdmUsageEntry&));
|
||||||
|
MOCK_METHOD2(UpdateUsageEntry,
|
||||||
|
CdmResponseType(CdmUsageTableHeader*, CdmUsageEntry*));
|
||||||
|
MOCK_METHOD1(MoveUsageEntry, CdmResponseType(uint32_t));
|
||||||
|
MOCK_METHOD2(ShrinkUsageTableHeader,
|
||||||
|
CdmResponseType(uint32_t, CdmUsageTableHeader*));
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestStubCryptoSessionFactory : public CryptoSessionFactory {
|
||||||
|
CryptoSession* MakeCryptoSession(metrics::CryptoMetrics* crypto_metrics) {
|
||||||
|
return new MockCryptoSession(crypto_metrics);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// gmock methods
|
||||||
|
using ::testing::_;
|
||||||
|
|
||||||
|
class CertificateProvisioningTest : public WvCdmTestBase {
|
||||||
|
public:
|
||||||
|
protected:
|
||||||
|
void SetUp() override {
|
||||||
|
WvCdmTestBase::SetUp();
|
||||||
|
CryptoSession::SetCryptoSessionFactory(new TestStubCryptoSessionFactory());
|
||||||
|
|
||||||
|
certificate_provisioning_.reset(
|
||||||
|
new CertificateProvisioning(new metrics::CryptoMetrics()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown() override {}
|
||||||
|
|
||||||
|
std::unique_ptr<CertificateProvisioning> certificate_provisioning_;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Tests ExtractDeviceInfo failure scenarios
|
||||||
|
// * invalid output parmeters
|
||||||
|
// * invalid signed drm device certificate
|
||||||
|
// * signed drm device certificate contains no drm certificate
|
||||||
|
// * drm certificate has an invalid certificate type
|
||||||
|
TEST_F(CertificateProvisioningTest, ExtractDeviceInfo_InvalidInput) {
|
||||||
|
std::string serial_number;
|
||||||
|
uint32_t system_id;
|
||||||
|
|
||||||
|
EXPECT_FALSE(certificate_provisioning_->ExtractDeviceInfo(
|
||||||
|
kSignedDeviceCertificate, nullptr, nullptr));
|
||||||
|
|
||||||
|
EXPECT_FALSE(certificate_provisioning_->ExtractDeviceInfo(
|
||||||
|
kSignedDeviceCertificateInvalid, &serial_number, &system_id));
|
||||||
|
|
||||||
|
EXPECT_FALSE(certificate_provisioning_->ExtractDeviceInfo(
|
||||||
|
kSignedDeviceCertificateNoDrmCertificate, &serial_number, &system_id));
|
||||||
|
|
||||||
|
EXPECT_FALSE(certificate_provisioning_->ExtractDeviceInfo(
|
||||||
|
kSignedDeviceCertificateInvalidCertificateType, &serial_number,
|
||||||
|
&system_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests ExtractDeviceInfo success scenarios
|
||||||
|
// * able to extract both |serial_number| and |system_id|
|
||||||
|
// * able to extract only |serial_number|
|
||||||
|
// * able to extract only |system_id|
|
||||||
|
TEST_F(CertificateProvisioningTest, ExtractDeviceInfo) {
|
||||||
|
std::string serial_number;
|
||||||
|
uint32_t system_id;
|
||||||
|
|
||||||
|
EXPECT_TRUE(certificate_provisioning_->ExtractDeviceInfo(
|
||||||
|
kSignedDeviceCertificate, &serial_number, &system_id));
|
||||||
|
EXPECT_EQ(kSerialNumber, serial_number);
|
||||||
|
EXPECT_EQ(kSystemId, system_id);
|
||||||
|
|
||||||
|
EXPECT_TRUE(certificate_provisioning_->ExtractDeviceInfo(
|
||||||
|
kSignedDeviceCertificate, nullptr, &system_id));
|
||||||
|
EXPECT_EQ(kSystemId, system_id);
|
||||||
|
|
||||||
|
EXPECT_TRUE(certificate_provisioning_->ExtractDeviceInfo(
|
||||||
|
kSignedDeviceCertificate, &serial_number, nullptr));
|
||||||
|
EXPECT_EQ(kSerialNumber, serial_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace wvcdm
|
||||||
@@ -45,6 +45,11 @@ test_src_dir := ../core/test
|
|||||||
test_main := ../core/test/test_main.cpp
|
test_main := ../core/test/test_main.cpp
|
||||||
include $(LOCAL_PATH)/integration-test.mk
|
include $(LOCAL_PATH)/integration-test.mk
|
||||||
|
|
||||||
|
test_name := certificate_provisioning_unittest
|
||||||
|
test_src_dir := ../core/test
|
||||||
|
test_main := ../core/test/test_main.cpp
|
||||||
|
include $(LOCAL_PATH)/integration-test.mk
|
||||||
|
|
||||||
test_name := counter_metric_unittest
|
test_name := counter_metric_unittest
|
||||||
test_src_dir := ../metrics/test
|
test_src_dir := ../metrics/test
|
||||||
include $(LOCAL_PATH)/unit-test.mk
|
include $(LOCAL_PATH)/unit-test.mk
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ adb_shell_run buffer_reader_test
|
|||||||
adb_shell_run cdm_engine_test
|
adb_shell_run cdm_engine_test
|
||||||
adb_shell_run cdm_engine_metrics_decorator_unittest
|
adb_shell_run cdm_engine_metrics_decorator_unittest
|
||||||
adb_shell_run cdm_session_unittest
|
adb_shell_run cdm_session_unittest
|
||||||
|
adb_shell_run certificate_provisioning_unittest
|
||||||
adb_shell_run counter_metric_unittest
|
adb_shell_run counter_metric_unittest
|
||||||
adb_shell_run crypto_session_unittest
|
adb_shell_run crypto_session_unittest
|
||||||
adb_shell_run device_files_unittest
|
adb_shell_run device_files_unittest
|
||||||
|
|||||||
Reference in New Issue
Block a user