mirror of
https://github.com/debauchee/barrier.git
synced 2026-07-04 19:06:45 +08:00
sending IV to client before DKDN, DKUP and DKRP (the most sensitive messages). unit tests to support changes. made crypto stream tests a bit less spammy by using NiceMock.
This commit is contained in:
@@ -20,6 +20,8 @@ set(h
|
||||
synergy/CMockKeyMap.h
|
||||
client/CMockClient.h
|
||||
io/CMockStream.h
|
||||
server/CMockServer.h
|
||||
io/CMockCryptoStream.h
|
||||
)
|
||||
|
||||
set(src
|
||||
@@ -29,12 +31,14 @@ set(src
|
||||
synergy/CKeyStateTests.cpp
|
||||
client/CServerProxyTests.cpp
|
||||
synergy/CCryptoStreamTests.cpp
|
||||
server/CClientProxyTests.cpp
|
||||
)
|
||||
|
||||
set(inc
|
||||
../../lib/arch
|
||||
../../lib/base
|
||||
../../lib/client
|
||||
../../lib/server
|
||||
../../lib/common
|
||||
../../lib/io
|
||||
../../lib/mt
|
||||
@@ -63,4 +67,4 @@ endif()
|
||||
include_directories(${inc})
|
||||
add_executable(unittests ${src})
|
||||
target_link_libraries(unittests
|
||||
arch base client common io net platform server synergy mt gtest gmock cryptopp ${libs})
|
||||
arch base client server common io net platform server synergy mt gtest gmock cryptopp ${libs})
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#define TEST_ENV
|
||||
#include "CClient.h"
|
||||
|
||||
class IEventQueue;
|
||||
@@ -26,6 +28,9 @@ class IEventQueue;
|
||||
class CMockClient : public CClient
|
||||
{
|
||||
public:
|
||||
CMockClient(IEventQueue& eventQueue) : CClient(eventQueue) { m_mock = true; }
|
||||
CMockClient() { m_mock = true; }
|
||||
MOCK_METHOD2(mouseMove, void(SInt32, SInt32));
|
||||
MOCK_METHOD1(setOptions, void(const COptionsList&));
|
||||
MOCK_METHOD0(handshakeComplete, void());
|
||||
MOCK_METHOD1(setCryptoIv, void(const UInt8*));
|
||||
};
|
||||
|
||||
@@ -16,11 +16,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define TEST_ENV
|
||||
#include "Global.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "CServerProxy.h"
|
||||
#include "CMockClient.h"
|
||||
#include "CMockStream.h"
|
||||
@@ -32,60 +30,77 @@ using ::testing::Invoke;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::AnyNumber;
|
||||
|
||||
int streamReads = 0;
|
||||
const UInt8 mouseMove_bufferLen = 16;
|
||||
UInt8 mouseMove_buffer[mouseMove_bufferLen];
|
||||
UInt32 mouseMove_bufferIndex = 0;
|
||||
UInt32 mouseMove_mockRead(void* buffer, UInt32 n);
|
||||
|
||||
UInt32
|
||||
streamRead(void* buffer, UInt32 n);
|
||||
const UInt8 cryptoIv_bufferLen = 20;
|
||||
UInt8 cryptoIv_buffer[cryptoIv_bufferLen];
|
||||
UInt32 cryptoIv_bufferIndex = 0;
|
||||
CString cryptoIv_result;
|
||||
UInt32 cryptoIv_mockRead(void* buffer, UInt32 n);
|
||||
void cryptoIv_setCryptoIv(const UInt8*);
|
||||
|
||||
// TODO: fix linking in windows (works in unix for some reason).
|
||||
#if 0
|
||||
TEST(CServerProxyTests, parseMessage_mouseMove_valuesCorrect)
|
||||
TEST(CServerProxyTests, mouseMove)
|
||||
{
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
CMockClient client(eventQueue);
|
||||
CMockStream stream(eventQueue);
|
||||
NiceMock<CMockClient> client;
|
||||
NiceMock<CMockStream> stream;
|
||||
|
||||
ON_CALL(stream, read(_, _)).WillByDefault(Invoke(streamRead));
|
||||
EXPECT_CALL(stream, read(_, _)).Times(4);
|
||||
EXPECT_CALL(stream, write(_, _)).Times(1);
|
||||
EXPECT_CALL(stream, isReady()).Times(1);
|
||||
EXPECT_CALL(stream, getEventTarget()).Times(AnyNumber());
|
||||
ON_CALL(stream, read(_, _)).WillByDefault(Invoke(mouseMove_mockRead));
|
||||
|
||||
EXPECT_CALL(client, mouseMove(1, 2)).Times(1);
|
||||
|
||||
const char data[] = "DSOP\0\0\0\0DMMV\0\1\0\2";
|
||||
memcpy(mouseMove_buffer, data, sizeof(data));
|
||||
|
||||
CServerProxy serverProxy(&client, &stream, eventQueue);
|
||||
|
||||
// skip handshake, go straight to normal parser.
|
||||
serverProxy.m_parser = &CServerProxy::parseMessage;
|
||||
|
||||
// assert
|
||||
EXPECT_CALL(client, mouseMove(10, 20));
|
||||
|
||||
serverProxy.handleData(NULL, NULL);
|
||||
CServerProxy serverProxy(&client, &stream, &eventQueue);
|
||||
serverProxy.handleDataForTest();
|
||||
}
|
||||
|
||||
TEST(CServerProxyTests, cryptoIv)
|
||||
{
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
NiceMock<CMockClient> client;
|
||||
NiceMock<CMockStream> stream;
|
||||
|
||||
ON_CALL(stream, read(_, _)).WillByDefault(Invoke(cryptoIv_mockRead));
|
||||
ON_CALL(client, setCryptoIv(_)).WillByDefault(Invoke(cryptoIv_setCryptoIv));
|
||||
|
||||
const char data[] = "DSOP\0\0\0\0DCIV\0\0\0\4mock";
|
||||
memcpy(cryptoIv_buffer, data, sizeof(data));
|
||||
|
||||
CServerProxy serverProxy(&client, &stream, &eventQueue);
|
||||
serverProxy.handleDataForTest();
|
||||
|
||||
EXPECT_EQ("mock", cryptoIv_result);
|
||||
}
|
||||
#endif
|
||||
|
||||
UInt32
|
||||
streamRead(void* buffer, UInt32 n)
|
||||
mouseMove_mockRead(void* buffer, UInt32 n)
|
||||
{
|
||||
streamReads++;
|
||||
UInt8* code = (UInt8*)buffer;
|
||||
|
||||
if (streamReads == 1) {
|
||||
code[0] = 'D';
|
||||
code[1] = 'M';
|
||||
code[2] = 'M';
|
||||
code[3] = 'V';
|
||||
return 4;
|
||||
if (mouseMove_bufferIndex >= mouseMove_bufferLen) {
|
||||
return 0;
|
||||
}
|
||||
else if (streamReads == 2) {
|
||||
code[0] = 0;
|
||||
code[1] = 10;
|
||||
return 2;
|
||||
}
|
||||
else if (streamReads == 3) {
|
||||
code[0] = 0;
|
||||
code[1] = 20;
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
memcpy(buffer, &mouseMove_buffer[mouseMove_bufferIndex], n);
|
||||
mouseMove_bufferIndex += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
UInt32
|
||||
cryptoIv_mockRead(void* buffer, UInt32 n)
|
||||
{
|
||||
if (cryptoIv_bufferIndex >= cryptoIv_bufferLen) {
|
||||
return 0;
|
||||
}
|
||||
memcpy(buffer, &cryptoIv_buffer[cryptoIv_bufferIndex], n);
|
||||
cryptoIv_bufferIndex += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
cryptoIv_setCryptoIv(const UInt8* data)
|
||||
{
|
||||
cryptoIv_result = reinterpret_cast<const char*>(data);
|
||||
}
|
||||
|
||||
29
src/test/unittests/io/CMockCryptoStream.h
Normal file
29
src/test/unittests/io/CMockCryptoStream.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2013 Bolton Software Ltd.
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file COPYING that should have accompanied this file.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "CCryptoStream.h"
|
||||
|
||||
class CMockCryptoStream : public CCryptoStream
|
||||
{
|
||||
public:
|
||||
CMockCryptoStream(IEventQueue* eventQueue, IStream* stream) : CCryptoStream(eventQueue, stream, false) { }
|
||||
MOCK_METHOD2(read, UInt32(void*, UInt32));
|
||||
MOCK_METHOD2(write, void(const void*, UInt32));
|
||||
};
|
||||
@@ -26,13 +26,17 @@ class IEventQueue;
|
||||
class CMockStream : public synergy::IStream
|
||||
{
|
||||
public:
|
||||
CMockStream(IEventQueue& eventQueue) : IStream(eventQueue) { }
|
||||
CMockStream() : synergy::IStream(NULL) { }
|
||||
MOCK_METHOD0(close, void());
|
||||
MOCK_METHOD2(read, UInt32(void*, UInt32));
|
||||
MOCK_METHOD2(write, void(const void*, UInt32));
|
||||
MOCK_METHOD0(flush, void());
|
||||
MOCK_METHOD0(shutdownInput, void());
|
||||
MOCK_METHOD0(shutdownOutput, void());
|
||||
MOCK_METHOD0(getInputReadyEvent, CEvent::Type());
|
||||
MOCK_METHOD0(getOutputErrorEvent, CEvent::Type());
|
||||
MOCK_METHOD0(getInputShutdownEvent, CEvent::Type());
|
||||
MOCK_METHOD0(getOutputShutdownEvent, CEvent::Type());
|
||||
MOCK_CONST_METHOD0(getEventTarget, void*());
|
||||
MOCK_CONST_METHOD0(isReady, bool());
|
||||
MOCK_CONST_METHOD0(getSize, UInt32());
|
||||
|
||||
96
src/test/unittests/server/CClientProxyTests.cpp
Normal file
96
src/test/unittests/server/CClientProxyTests.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2013 Bolton Software Ltd.
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file COPYING that should have accompanied this file.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "CClientProxy1_4.h"
|
||||
#include "CMockServer.h"
|
||||
#include "CMockStream.h"
|
||||
#include "CMockCryptoStream.h"
|
||||
#include "CMockEventQueue.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::Invoke;
|
||||
|
||||
const byte g_key[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; // +\0, 32-byte/256-bit key.
|
||||
const byte g_iv[] = "bbbbbbbbbbbbbb"; // +\0, AES block size = 16
|
||||
|
||||
const UInt8 cryptoIvWrite_bufferLen = 200;
|
||||
UInt8 cryptoIvWrite_buffer[cryptoIvWrite_bufferLen];
|
||||
UInt32 cryptoIvWrite_bufferIndex = 0;
|
||||
|
||||
void
|
||||
cryptoIv_mockWrite(const void* in, UInt32 n);
|
||||
|
||||
TEST(CClientProxyTests, cryptoIvWrite)
|
||||
{
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
NiceMock<CMockStream> innerStream;
|
||||
NiceMock<CMockServer> server;
|
||||
NiceMock<CMockCryptoStream>* stream = new NiceMock<CMockCryptoStream>(&eventQueue, &innerStream);
|
||||
stream->setKeyWithIv(g_key, sizeof(g_key), g_iv);
|
||||
|
||||
ON_CALL(*stream, write(_, _)).WillByDefault(Invoke(cryptoIv_mockWrite));
|
||||
|
||||
CClientProxy1_4 clientProxy("stub", stream, &server, &eventQueue);
|
||||
|
||||
// DCIV, then DKDN.
|
||||
cryptoIvWrite_bufferIndex = 0;
|
||||
clientProxy.keyDown(1, 2, 3);
|
||||
EXPECT_EQ('D', cryptoIvWrite_buffer[0]);
|
||||
EXPECT_EQ('C', cryptoIvWrite_buffer[1]);
|
||||
EXPECT_EQ('I', cryptoIvWrite_buffer[2]);
|
||||
EXPECT_EQ('V', cryptoIvWrite_buffer[3]);
|
||||
EXPECT_EQ('D', cryptoIvWrite_buffer[24]);
|
||||
EXPECT_EQ('K', cryptoIvWrite_buffer[25]);
|
||||
EXPECT_EQ('D', cryptoIvWrite_buffer[26]);
|
||||
EXPECT_EQ('N', cryptoIvWrite_buffer[27]);
|
||||
|
||||
// DCIV, then DKUP.
|
||||
cryptoIvWrite_bufferIndex = 0;
|
||||
clientProxy.keyUp(1, 2, 3);
|
||||
EXPECT_EQ('D', cryptoIvWrite_buffer[0]);
|
||||
EXPECT_EQ('C', cryptoIvWrite_buffer[1]);
|
||||
EXPECT_EQ('I', cryptoIvWrite_buffer[2]);
|
||||
EXPECT_EQ('V', cryptoIvWrite_buffer[3]);
|
||||
EXPECT_EQ('D', cryptoIvWrite_buffer[24]);
|
||||
EXPECT_EQ('K', cryptoIvWrite_buffer[25]);
|
||||
EXPECT_EQ('U', cryptoIvWrite_buffer[26]);
|
||||
EXPECT_EQ('P', cryptoIvWrite_buffer[27]);
|
||||
|
||||
// DCIV, then DKRP.
|
||||
cryptoIvWrite_bufferIndex = 0;
|
||||
clientProxy.keyRepeat(1, 2, 4, 4);
|
||||
EXPECT_EQ('D', cryptoIvWrite_buffer[0]);
|
||||
EXPECT_EQ('C', cryptoIvWrite_buffer[1]);
|
||||
EXPECT_EQ('I', cryptoIvWrite_buffer[2]);
|
||||
EXPECT_EQ('V', cryptoIvWrite_buffer[3]);
|
||||
EXPECT_EQ('D', cryptoIvWrite_buffer[24]);
|
||||
EXPECT_EQ('K', cryptoIvWrite_buffer[25]);
|
||||
EXPECT_EQ('R', cryptoIvWrite_buffer[26]);
|
||||
EXPECT_EQ('P', cryptoIvWrite_buffer[27]);
|
||||
}
|
||||
|
||||
void
|
||||
cryptoIv_mockWrite(const void* in, UInt32 n)
|
||||
{
|
||||
if (cryptoIvWrite_bufferIndex >= cryptoIvWrite_bufferLen) {
|
||||
return;
|
||||
}
|
||||
memcpy(&cryptoIvWrite_buffer[cryptoIvWrite_bufferIndex], in, n);
|
||||
cryptoIvWrite_bufferIndex += n;
|
||||
}
|
||||
31
src/test/unittests/server/CMockServer.h
Normal file
31
src/test/unittests/server/CMockServer.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2013 Bolton Software Ltd.
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file COPYING that should have accompanied this file.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#define TEST_ENV
|
||||
#include "CServer.h"
|
||||
|
||||
class IEventQueue;
|
||||
|
||||
class CMockServer : public CServer
|
||||
{
|
||||
public:
|
||||
CMockServer() : CServer() { }
|
||||
};
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::NiceMock;
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -64,17 +65,12 @@ TEST(CCryptoTests, write)
|
||||
buffer[2] = 'D';
|
||||
buffer[3] = 'N';
|
||||
|
||||
CMockEventQueue eventQueue;
|
||||
CMockStream innerStream(eventQueue);
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
NiceMock<CMockStream> innerStream;
|
||||
|
||||
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(write_mockWrite));
|
||||
EXPECT_CALL(innerStream, write(_, _)).Times(1);
|
||||
EXPECT_CALL(innerStream, getEventTarget()).Times(3);
|
||||
EXPECT_CALL(eventQueue, removeHandlers(_)).Times(1);
|
||||
EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(1);
|
||||
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(1);
|
||||
|
||||
CCryptoStream cs(eventQueue, &innerStream, false);
|
||||
CCryptoStream cs(&eventQueue, &innerStream, false);
|
||||
cs.setKeyWithIv(g_key, sizeof(g_key), g_iv);
|
||||
cs.write(buffer, size);
|
||||
|
||||
@@ -86,17 +82,12 @@ TEST(CCryptoTests, write)
|
||||
|
||||
TEST(CCryptoTests, read)
|
||||
{
|
||||
CMockEventQueue eventQueue;
|
||||
CMockStream innerStream(eventQueue);
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
NiceMock<CMockStream> innerStream;
|
||||
|
||||
ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(read_mockRead));
|
||||
EXPECT_CALL(innerStream, read(_, _)).Times(1);
|
||||
EXPECT_CALL(innerStream, getEventTarget()).Times(3);
|
||||
EXPECT_CALL(eventQueue, removeHandlers(_)).Times(1);
|
||||
EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(1);
|
||||
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(1);
|
||||
|
||||
CCryptoStream cs(eventQueue, &innerStream, false);
|
||||
CCryptoStream cs(&eventQueue, &innerStream, false);
|
||||
cs.setKeyWithIv(g_key, sizeof(g_key), g_iv);
|
||||
|
||||
g_read_buffer[0] = 254;
|
||||
@@ -116,19 +107,13 @@ TEST(CCryptoTests, read)
|
||||
|
||||
TEST(CCryptoTests, write4Read1)
|
||||
{
|
||||
CMockEventQueue eventQueue;
|
||||
CMockStream innerStream(eventQueue);
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
NiceMock<CMockStream> innerStream;
|
||||
|
||||
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(write4Read1_mockWrite));
|
||||
ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(write4Read1_mockRead));
|
||||
EXPECT_CALL(innerStream, write(_, _)).Times(4);
|
||||
EXPECT_CALL(innerStream, read(_, _)).Times(1);
|
||||
EXPECT_CALL(innerStream, getEventTarget()).Times(6);
|
||||
EXPECT_CALL(eventQueue, removeHandlers(_)).Times(2);
|
||||
EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2);
|
||||
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2);
|
||||
|
||||
CCryptoStream cs1(eventQueue, &innerStream, false);
|
||||
CCryptoStream cs1(&eventQueue, &innerStream, false);
|
||||
cs1.setKeyWithIv(g_key, sizeof(g_key), g_iv);
|
||||
|
||||
cs1.write("a", 1);
|
||||
@@ -136,7 +121,7 @@ TEST(CCryptoTests, write4Read1)
|
||||
cs1.write("c", 1);
|
||||
cs1.write("d", 1);
|
||||
|
||||
CCryptoStream cs2(eventQueue, &innerStream, false);
|
||||
CCryptoStream cs2(&eventQueue, &innerStream, false);
|
||||
cs2.setKeyWithIv(g_key, sizeof(g_key), g_iv);
|
||||
|
||||
UInt8 buffer[4];
|
||||
@@ -150,19 +135,13 @@ TEST(CCryptoTests, write4Read1)
|
||||
|
||||
TEST(CCryptoTests, write1Read4)
|
||||
{
|
||||
CMockEventQueue eventQueue;
|
||||
CMockStream innerStream(eventQueue);
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
NiceMock<CMockStream> innerStream;
|
||||
|
||||
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(write1Read4_mockWrite));
|
||||
ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(write1Read4_mockRead));
|
||||
EXPECT_CALL(innerStream, write(_, _)).Times(1);
|
||||
EXPECT_CALL(innerStream, read(_, _)).Times(4);
|
||||
EXPECT_CALL(innerStream, getEventTarget()).Times(6);
|
||||
EXPECT_CALL(eventQueue, removeHandlers(_)).Times(2);
|
||||
EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2);
|
||||
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2);
|
||||
|
||||
CCryptoStream cs1(eventQueue, &innerStream, false);
|
||||
CCryptoStream cs1(&eventQueue, &innerStream, false);
|
||||
cs1.setKeyWithIv(g_key, sizeof(g_key), g_iv);
|
||||
|
||||
UInt8 bufferIn[4];
|
||||
@@ -172,7 +151,7 @@ TEST(CCryptoTests, write1Read4)
|
||||
bufferIn[3] = 'd';
|
||||
cs1.write(bufferIn, 4);
|
||||
|
||||
CCryptoStream cs2(eventQueue, &innerStream, false);
|
||||
CCryptoStream cs2(&eventQueue, &innerStream, false);
|
||||
cs2.setKeyWithIv(g_key, sizeof(g_key), g_iv);
|
||||
|
||||
UInt8 bufferOut[4];
|
||||
@@ -189,22 +168,16 @@ TEST(CCryptoTests, write1Read4)
|
||||
|
||||
TEST(CCryptoTests, readWriteIvChanged)
|
||||
{
|
||||
CMockEventQueue eventQueue;
|
||||
CMockStream innerStream(eventQueue);
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
NiceMock<CMockStream> innerStream;
|
||||
|
||||
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(readWriteIvChanged_mockWrite));
|
||||
ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(readWriteIvChanged_mockRead));
|
||||
EXPECT_CALL(innerStream, write(_, _)).Times(2);
|
||||
EXPECT_CALL(innerStream, read(_, _)).Times(2);
|
||||
EXPECT_CALL(innerStream, getEventTarget()).Times(6);
|
||||
EXPECT_CALL(eventQueue, removeHandlers(_)).Times(2);
|
||||
EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2);
|
||||
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2);
|
||||
|
||||
const byte iv1[] = "bbbbbbbbbbbbbbb";
|
||||
const byte iv2[] = "ccccccccccccccc";
|
||||
|
||||
CCryptoStream cs1(eventQueue, &innerStream, false);
|
||||
CCryptoStream cs1(&eventQueue, &innerStream, false);
|
||||
cs1.setKeyWithIv(g_key, sizeof(g_key), iv1);
|
||||
|
||||
UInt8 bufferIn[4];
|
||||
@@ -214,7 +187,7 @@ TEST(CCryptoTests, readWriteIvChanged)
|
||||
bufferIn[3] = 'd';
|
||||
cs1.write(bufferIn, 4);
|
||||
|
||||
CCryptoStream cs2(eventQueue, &innerStream, false);
|
||||
CCryptoStream cs2(&eventQueue, &innerStream, false);
|
||||
cs2.setKeyWithIv(g_key, sizeof(g_key), iv2);
|
||||
|
||||
UInt8 bufferOut[4];
|
||||
@@ -296,8 +269,6 @@ readWriteIvChanged_mockRead(void* out, UInt32 n)
|
||||
return n;
|
||||
}
|
||||
|
||||
// TODO: macro?
|
||||
|
||||
void
|
||||
readWriteIvChangeTrigger_mockWrite(const void* in, UInt32 n)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user