Allow 1 or 2 GetOEMPublicCertificate Calls in Metrics Tests

(This is a merge of http://go/wvgerrit/107263.)

The CryptoSessionMetricsTest suite assumed that GetOEMPublicCertificate
would only be called once, but in practice, it may be called twice,
since the first call can return OEMCrypto_ERROR_SHORT_BUFFER. This patch
updates the tests to accept 1 or 2 calls.

This patch also updates a few EXPECTs on vector lengths that should have
been ASSERTs, to avoid problems when later accessing the vector.

Bug: 169111969
Test: jenkins/ce_cdm_tests
Test: build_and_run_all_unit_tests.sh
Change-Id: I9432dd2694c7181ab57ed55f66ff6c8be0c867f9
This commit is contained in:
John W. Bruce
2020-10-06 14:42:54 -07:00
parent 48122e2c11
commit 25489dfa5b

View File

@@ -5,6 +5,7 @@
#include <memory>
#include <string>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "crypto_session.h"
@@ -19,6 +20,10 @@
#include "wv_cdm_types.h"
#include "wv_metrics.pb.h"
using ::testing::AllOf;
using ::testing::Ge;
using ::testing::Le;
namespace {
const uint8_t kOemCert[] = {
@@ -296,7 +301,7 @@ TEST_F(CryptoSessionMetricsTest, OpenSessionValidMetrics) {
// lite, convert these tests to use Message-based convenience functions.
// Validate common metrics regardless of provisioning type.
EXPECT_EQ(1, metrics_proto.oemcrypto_initialize_time_us().size());
ASSERT_EQ(1, metrics_proto.oemcrypto_initialize_time_us().size());
EXPECT_TRUE(metrics_proto.oemcrypto_initialize_time_us(0)
.attributes()
.has_oem_crypto_result());
@@ -327,7 +332,8 @@ TEST_F(CryptoSessionMetricsTest, OpenSessionValidMetrics) {
EXPECT_EQ(OEMCrypto_OEMCertificate,
metrics_proto.oemcrypto_provisioning_method().int_value());
ASSERT_EQ(1, metrics_proto.oemcrypto_get_oem_public_certificate().size());
EXPECT_EQ(1, metrics_proto.oemcrypto_get_oem_public_certificate(0).count());
EXPECT_THAT(metrics_proto.oemcrypto_get_oem_public_certificate(0).count(),
AllOf(Ge(1), Le(2)));
} else if (token_type == kClientTokenDrmCert) {
// TODO(blueeyes): Add support for getting the system id from a
// pre-installed DRM certificate..
@@ -373,8 +379,9 @@ TEST_F(CryptoSessionMetricsTest, GetProvisioningTokenValidMetrics) {
EXPECT_EQ(OEMCrypto_OEMCertificate,
metrics_proto.oemcrypto_provisioning_method().int_value());
EXPECT_EQ(1, metrics_proto.oemcrypto_get_oem_public_certificate().size());
EXPECT_EQ(1, metrics_proto.oemcrypto_get_oem_public_certificate(0).count());
ASSERT_EQ(1, metrics_proto.oemcrypto_get_oem_public_certificate().size());
EXPECT_THAT(metrics_proto.oemcrypto_get_oem_public_certificate(0).count(),
AllOf(Ge(1), Le(2)));
ASSERT_EQ(1, metrics_proto.crypto_session_get_token().size());
EXPECT_EQ(1, metrics_proto.crypto_session_get_token(0).count());