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

Unified Diff: components/cryptauth/device_to_device_secure_context_unittest.cc

Issue 2899863002: Updating D2D protocol to v1 to support separate sequence numbers. (Closed)
Patch Set: Fixing tests Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/cryptauth/device_to_device_secure_context_unittest.cc
diff --git a/components/cryptauth/device_to_device_secure_context_unittest.cc b/components/cryptauth/device_to_device_secure_context_unittest.cc
index 12c1994fa208f5c4b50f9e6faf475b68db457781..7569b617569123cd373b13bc9425615c096eac48 100644
--- a/components/cryptauth/device_to_device_secure_context_unittest.cc
+++ b/components/cryptauth/device_to_device_secure_context_unittest.cc
@@ -11,6 +11,7 @@
#include "components/cryptauth/fake_secure_message_delegate.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h"
#include "components/cryptauth/proto/securemessage.pb.h"
+#include "components/cryptauth/session_keys.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cryptauth {
@@ -27,16 +28,30 @@ void SaveResult(std::string* result_out, const std::string& result) {
*result_out = result;
}
+// The responder's secure context will have the encoding / decoding keys
+// inverted.
+class InvertedSessionKeys : public SessionKeys {
+ public:
+ explicit InvertedSessionKeys(const std::string& master_symmetric_key)
+ : SessionKeys(master_symmetric_key) {}
+
+ std::string initiator_encode_key() const override {
+ return SessionKeys::responder_encode_key();
+ }
+ std::string responder_encode_key() const override {
+ return SessionKeys::initiator_encode_key();
+ }
+};
+
} // namespace
class ProximityAuthDeviceToDeviceSecureContextTest : public testing::Test {
protected:
ProximityAuthDeviceToDeviceSecureContextTest()
- : secure_context_(
- base::MakeUnique<FakeSecureMessageDelegate>(),
- kSymmetricKey,
- kResponderAuthMessage,
- kProtocolVersion) {}
+ : secure_context_(base::MakeUnique<FakeSecureMessageDelegate>(),
+ base::MakeUnique<SessionKeys>(kSymmetricKey),
+ kResponderAuthMessage,
+ kProtocolVersion) {}
DeviceToDeviceSecureContext secure_context_;
};
@@ -75,7 +90,8 @@ TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, DecodeInvalidMessage) {
TEST_F(ProximityAuthDeviceToDeviceSecureContextTest, EncodeAndDecode) {
// Initialize second secure channel with the same parameters as the first.
DeviceToDeviceSecureContext secure_context2(
- base::MakeUnique<FakeSecureMessageDelegate>(), kSymmetricKey,
+ base::MakeUnique<FakeSecureMessageDelegate>(),
+ base::MakeUnique<InvertedSessionKeys>(kSymmetricKey),
kResponderAuthMessage, kProtocolVersion);
std::string message = "encrypt this message";
@@ -96,7 +112,8 @@ TEST_F(ProximityAuthDeviceToDeviceSecureContextTest,
DecodeInvalidSequenceNumber) {
// Initialize second secure channel with the same parameters as the first.
DeviceToDeviceSecureContext secure_context2(
- base::MakeUnique<FakeSecureMessageDelegate>(), kSymmetricKey,
+ base::MakeUnique<FakeSecureMessageDelegate>(),
+ base::MakeUnique<InvertedSessionKeys>(kSymmetricKey),
kResponderAuthMessage, kProtocolVersion);
// Send a few messages over the first secure context.

Powered by Google App Engine
This is Rietveld 408576698