Skip to content

Commit 3a5aa65

Browse files
ejohnstownpadelsbach
authored andcommitted
Small Test Reorganization
1. Collect all the test function wrappers in internal.c to one location at the end of the file. 2. Update API test to check other algos if RSA or ECDSA are disabled. 3. Added guarded tests TestClientBuffersIdempotent() for WOLFSSH_NO_RSA and WOLFSSH_NO_ECDSA_SHA2_NISTP256. If both are set, the test is skipped.
1 parent fdf621c commit 3a5aa65

3 files changed

Lines changed: 128 additions & 82 deletions

File tree

src/internal.c

Lines changed: 73 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -853,37 +853,6 @@ INLINE static int IsMessageAllowed(WOLFSSH *ssh, byte msg, byte state)
853853
return 0;
854854
}
855855

856-
#ifdef WOLFSSH_TEST_INTERNAL
857-
int wolfSSH_TestIsMessageAllowed(WOLFSSH* ssh, byte msg, byte state)
858-
{
859-
return IsMessageAllowed(ssh, msg, state);
860-
}
861-
862-
static int DoKexInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx);
863-
static int DoKexDhInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx);
864-
#ifndef WOLFSSH_NO_DH_GEX_SHA256
865-
static int DoKexDhGexRequest(WOLFSSH* ssh, byte* buf, word32 len, word32* idx);
866-
#endif
867-
868-
int wolfSSH_TestDoKexInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
869-
{
870-
return DoKexInit(ssh, buf, len, idx);
871-
}
872-
873-
int wolfSSH_TestDoKexDhInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
874-
{
875-
return DoKexDhInit(ssh, buf, len, idx);
876-
}
877-
878-
#ifndef WOLFSSH_NO_DH_GEX_SHA256
879-
int wolfSSH_TestDoKexDhGexRequest(WOLFSSH* ssh, byte* buf, word32 len,
880-
word32* idx)
881-
{
882-
return DoKexDhGexRequest(ssh, buf, len, idx);
883-
}
884-
#endif
885-
#endif
886-
887856

888857
static const char cannedKexAlgoNames[] =
889858
#if !defined(WOLFSSH_NO_CURVE25519_MLKEM768_SHA256)
@@ -6558,15 +6527,6 @@ static int DoKexDhGexGroup(WOLFSSH* ssh,
65586527
return ret;
65596528
}
65606529

6561-
#ifdef WOLFSSH_TEST_INTERNAL
6562-
int wolfSSH_TestValidateKexDhGexGroup(const byte* primeGroup,
6563-
word32 primeGroupSz, const byte* generator, word32 generatorSz,
6564-
word32 minBits, word32 maxBits, WC_RNG* rng)
6565-
{
6566-
return ValidateKexDhGexGroup(primeGroup, primeGroupSz,
6567-
generator, generatorSz, minBits, maxBits, rng);
6568-
}
6569-
#endif
65706530
#endif /* !WOLFSSH_NO_DH_GEX_SHA256 */
65716531

65726532

@@ -10750,31 +10710,6 @@ int DoReceive(WOLFSSH* ssh)
1075010710
return ret;
1075110711
}
1075210712

10753-
#ifdef WOLFSSH_TEST_INTERNAL
10754-
int wolfSSH_TestDoReceive(WOLFSSH* ssh)
10755-
{
10756-
return DoReceive(ssh);
10757-
}
10758-
10759-
int wolfSSH_TestDoUserAuthBanner(WOLFSSH* ssh, byte* buf, word32 len,
10760-
word32* idx)
10761-
{
10762-
return DoUserAuthBanner(ssh, buf, len, idx);
10763-
}
10764-
10765-
int wolfSSH_TestDoChannelRequest(WOLFSSH* ssh, byte* buf, word32 len,
10766-
word32* idx)
10767-
{
10768-
return DoChannelRequest(ssh, buf, len, idx);
10769-
}
10770-
10771-
int wolfSSH_TestChannelPutData(WOLFSSH_CHANNEL* channel, byte* data,
10772-
word32 dataSz)
10773-
{
10774-
return ChannelPutData(channel, data, dataSz);
10775-
}
10776-
#endif
10777-
1077810713

1077910714
int DoProtoId(WOLFSSH* ssh)
1078010715
{
@@ -11968,15 +11903,6 @@ int wolfSSH_RsaVerify(const byte *sig, word32 sigSz,
1196811903
return ret;
1196911904
}
1197011905

11971-
#ifdef WOLFSSH_TEST_INTERNAL
11972-
int wolfSSH_TestRsaVerify(const byte* sig, word32 sigSz,
11973-
const byte* encDigest, word32 encDigestSz,
11974-
RsaKey* key, void* heap)
11975-
{
11976-
return wolfSSH_RsaVerify(sig, sigSz, encDigest, encDigestSz,
11977-
key, heap, "wolfSSH_TestRsaVerify");
11978-
}
11979-
#endif /* WOLFSSH_TEST_INTERNAL */
1198011906
#endif /* WOLFSSH_NO_RSA */
1198111907

1198211908

@@ -17933,3 +17859,76 @@ void AddAssign64(word32* addend1, word32 addend2)
1793317859
}
1793417860

1793517861
#endif /* WOLFSSH_SFTP */
17862+
17863+
17864+
#ifdef WOLFSSH_TEST_INTERNAL
17865+
17866+
int wolfSSH_TestIsMessageAllowed(WOLFSSH* ssh, byte msg, byte state)
17867+
{
17868+
return IsMessageAllowed(ssh, msg, state);
17869+
}
17870+
17871+
int wolfSSH_TestDoReceive(WOLFSSH* ssh)
17872+
{
17873+
return DoReceive(ssh);
17874+
}
17875+
17876+
int wolfSSH_TestDoUserAuthBanner(WOLFSSH* ssh, byte* buf, word32 len,
17877+
word32* idx)
17878+
{
17879+
return DoUserAuthBanner(ssh, buf, len, idx);
17880+
}
17881+
17882+
int wolfSSH_TestDoChannelRequest(WOLFSSH* ssh, byte* buf, word32 len,
17883+
word32* idx)
17884+
{
17885+
return DoChannelRequest(ssh, buf, len, idx);
17886+
}
17887+
17888+
int wolfSSH_TestDoKexInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
17889+
{
17890+
return DoKexInit(ssh, buf, len, idx);
17891+
}
17892+
17893+
int wolfSSH_TestDoKexDhInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
17894+
{
17895+
return DoKexDhInit(ssh, buf, len, idx);
17896+
}
17897+
17898+
int wolfSSH_TestChannelPutData(WOLFSSH_CHANNEL* channel, byte* data,
17899+
word32 dataSz)
17900+
{
17901+
return ChannelPutData(channel, data, dataSz);
17902+
}
17903+
17904+
#ifndef WOLFSSH_NO_DH_GEX_SHA256
17905+
17906+
int wolfSSH_TestDoKexDhGexRequest(WOLFSSH* ssh, byte* buf, word32 len,
17907+
word32* idx)
17908+
{
17909+
return DoKexDhGexRequest(ssh, buf, len, idx);
17910+
}
17911+
17912+
int wolfSSH_TestValidateKexDhGexGroup(const byte* primeGroup,
17913+
word32 primeGroupSz, const byte* generator, word32 generatorSz,
17914+
word32 minBits, word32 maxBits, WC_RNG* rng)
17915+
{
17916+
return ValidateKexDhGexGroup(primeGroup, primeGroupSz,
17917+
generator, generatorSz, minBits, maxBits, rng);
17918+
}
17919+
17920+
#endif /* !WOLFSSH_NO_DH_GEX_SHA256 */
17921+
17922+
#ifndef WOLFSSH_NO_RSA
17923+
17924+
int wolfSSH_TestRsaVerify(const byte* sig, word32 sigSz,
17925+
const byte* encDigest, word32 encDigestSz,
17926+
RsaKey* key, void* heap)
17927+
{
17928+
return wolfSSH_RsaVerify(sig, sigSz, encDigest, encDigestSz,
17929+
key, heap, "wolfSSH_TestRsaVerify");
17930+
}
17931+
17932+
#endif /* !WOLFSSH_NO_RSA */
17933+
17934+
#endif /* WOLFSSH_TEST_INTERNAL */

tests/api.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,30 @@ static void test_wolfSSH_QueryAlgoList(void)
18551855
AssertNull(name);
18561856

18571857
k = wolfSSH_CheckAlgoName("ssh-rsa");
1858+
#ifndef WOLFSSH_NO_SSH_RSA_SHA1
1859+
AssertIntEQ(WS_SUCCESS, k);
1860+
#else
1861+
AssertIntEQ(WS_INVALID_ALGO_ID, k);
1862+
#endif /* WOLFSSH_NO_SSH_RSA_SHA1 */
1863+
1864+
k = wolfSSH_CheckAlgoName("ecdsa-sha2-nistp256");
1865+
#ifndef WOLFSSH_NO_ECDSA_SHA2_NISTP256
1866+
AssertIntEQ(WS_SUCCESS, k);
1867+
#else
1868+
AssertIntEQ(WS_INVALID_ALGO_ID, k);
1869+
#endif /* WOLFSSH_NO_ECDSA_SHA2_NISTP256 */
1870+
1871+
k = wolfSSH_CheckAlgoName("diffie-hellman-group14-sha256");
1872+
#ifndef WOLFSSH_NO_DH_GROUP14_SHA256
1873+
AssertIntEQ(WS_SUCCESS, k);
1874+
#else
1875+
AssertIntEQ(WS_INVALID_ALGO_ID, k);
1876+
#endif /* WOLFSSH_NO_DH_GROUP14_SHA256 */
1877+
1878+
k = wolfSSH_CheckAlgoName("server-sig-algs");
1879+
AssertIntEQ(WS_SUCCESS, k);
1880+
1881+
k = wolfSSH_CheckAlgoName("nistp256");
18581882
AssertIntEQ(WS_SUCCESS, k);
18591883

18601884
k = wolfSSH_CheckAlgoName("not-an-algo@wolfssl.com");

tests/regress.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,20 +1644,41 @@ static void TestSftpRemoveHandleHeadUpdate(void)
16441644
#endif
16451645
#endif
16461646

1647+
#if !(defined(WOLFSSH_NO_RSA) && defined(WOLFSSH_NO_ECDSA_SHA2_NISTP256))
16471648
/* Ensure client buffer cleanup tolerates multiple invocations after allocs. */
16481649
static void TestClientBuffersIdempotent(void)
16491650
{
1650-
int ret;
1651+
#ifndef WOLFSSH_NO_RSA
1652+
{
1653+
int ret;
16511654

1652-
ret = ClientUsePubKey("keys/gretel-key-rsa.pub");
1653-
AssertIntEQ(ret, 0);
1654-
ret = ClientSetPrivateKey("keys/gretel-key-rsa.pem");
1655-
AssertIntEQ(ret, 0);
1655+
ret = ClientUsePubKey("keys/gretel-key-rsa.pub");
1656+
AssertIntEQ(ret, 0);
1657+
ret = ClientSetPrivateKey("keys/gretel-key-rsa.pem");
1658+
AssertIntEQ(ret, 0);
16561659

1657-
ClientFreeBuffers();
1658-
/* Should be safe to call again without double free. */
1659-
ClientFreeBuffers();
1660+
ClientFreeBuffers();
1661+
/* Should be safe to call again without double free. */
1662+
ClientFreeBuffers();
1663+
}
1664+
#endif
1665+
1666+
#ifndef WOLFSSH_NO_ECDSA_SHA2_NISTP256
1667+
{
1668+
int ret;
1669+
1670+
ret = ClientUsePubKey("keys/gretel-key-ecc.pub");
1671+
AssertIntEQ(ret, 0);
1672+
ret = ClientSetPrivateKey("keys/gretel-key-ecc.pem");
1673+
AssertIntEQ(ret, 0);
1674+
1675+
ClientFreeBuffers();
1676+
/* Should be safe to call again without double free. */
1677+
ClientFreeBuffers();
1678+
}
1679+
#endif
16601680
}
1681+
#endif
16611682

16621683
/* Simulate Ctrl+D (stdin EOF) during password prompt; expect failure but no crash. */
16631684
static void TestPasswordEofNoCrash(void)
@@ -2157,7 +2178,9 @@ int main(int argc, char** argv)
21572178
TestFirstPacketFollows();
21582179
#endif
21592180
TestDisconnectSetsDisconnectError();
2181+
#if !(defined(WOLFSSH_NO_RSA) && defined(WOLFSSH_NO_ECDSA_SHA2_NISTP256))
21602182
TestClientBuffersIdempotent();
2183+
#endif
21612184
TestPasswordEofNoCrash();
21622185
#ifndef WOLFSSH_TEST_BLOCK
21632186
TestWorkerReadsWhenSendWouldBlock();

0 commit comments

Comments
 (0)