//////////////////////////////////////////////////////////////////////////////// // Copyright 2019 Google LLC. // // This software is licensed under the terms defined in the Widevine Master // License Agreement. For a copy of this agreement, please contact // widevine-licensing@google.com. //////////////////////////////////////////////////////////////////////////////// // // Description: // Unit tests for the rot_id_util helper methods. #include "common/rot_id_util.h" #include "testing/gmock.h" #include "testing/gunit.h" #include "absl/strings/escaping.h" namespace { constexpr char kFakeEncryptedId[] = "fake encrypted id"; constexpr char kFakeUniqueIdHash[] = "fake unique_id hash"; // This is the ROT ID Hash generated from the fake values. constexpr char kRotIdHashHex[] = "0a757dde0f1080b60f34bf8e46af573ce987b5ed1c831b44952e2feed5243a95"; constexpr uint32_t kFakeSystemId = 1234; constexpr uint32_t kOtherFakeSystemId = 9876; } // anonymous namespace namespace widevine { TEST(RotIdUtilTest, IsRotIdRevokedMatches) { ASSERT_TRUE(IsRotIdRevoked>( kFakeEncryptedId, kFakeSystemId, absl::HexStringToBytes(kRotIdHashHex), {"NO MATCH UNIQUE ID HASH 1", kFakeUniqueIdHash})); } TEST(RotIdUtilTest, IsRotIdRevokedNoMatchSystemId) { ASSERT_FALSE(IsRotIdRevoked>( kFakeEncryptedId, kOtherFakeSystemId, absl::HexStringToBytes(kRotIdHashHex), {"NO MATCH UNIQUE ID HASH 1", kFakeUniqueIdHash})); } TEST(RotIdUtilTest, IsRotIdRevokedNoMatch) { ASSERT_FALSE(IsRotIdRevoked>( kFakeEncryptedId, kFakeSystemId, kFakeUniqueIdHash, {"NO MATCH UNIQUE ID HASH 1", "NO MATCH UNIQUE ID HASH 2"})); } TEST(RotIdUtilTest, IsRotIdRevokedEmptyList) { ASSERT_FALSE(IsRotIdRevoked>( kFakeEncryptedId, kFakeSystemId, kFakeUniqueIdHash, {/* Intentionally empty vector */})); } // This test really only ensures the stability of the implementation. If the // hash ever changes, then it will introduce problems into the ecosystem. TEST(RotIdUtilTest, GenerateRotIdHashSuccess) { ASSERT_EQ( absl::HexStringToBytes(kRotIdHashHex), GenerateRotIdHash(kFakeEncryptedId, kFakeSystemId, kFakeUniqueIdHash)); } } // namespace widevine