Skip to content

Commit 0bb6146

Browse files
Clang-format tests/unit/s2n_[t-z].*\.c and enforce in CI (#3679)
1 parent 06e9e8c commit 0bb6146

35 files changed

+995
-1005
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,6 @@ Standard: Auto
138138
StatementMacros:
139139
- Q_UNUSED
140140
- QT_REQUIRE_VERSION
141+
- test_stack_blob_success
141142
TabWidth: 8
142143
UseTab: Never

.github/workflows/ci_clang_format_check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- check: 'tests/testlib'
1919
exclude: ''
2020
- check: 'tests/unit'
21-
exclude: "s2n_[^3a-cd-k].*\\.c"
21+
exclude: "s2n_[^3a-cd-kt-z].*\\.c"
2222
- check: 'tls'
2323
exclude: "(tls\\/extensions)|(s2n_[a-hs-z].*\\.[ch])"
2424
- check: 'tls/extensions'

tests/unit/s2n_testlib_test.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
#include "s2n_test.h"
17-
1816
#include "testlib/s2n_testlib.h"
1917

18+
#include "s2n_test.h"
19+
2020
int main(int argc, char **argv)
2121
{
2222
BEGIN_TEST();
@@ -41,7 +41,7 @@ int main(int argc, char **argv)
4141
EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate_test_server_and_client(server_conn, NULL), S2N_ERR_NULL);
4242

4343
EXPECT_SUCCESS(s2n_connection_free(server_conn));
44-
}
44+
};
4545

4646
END_TEST();
4747
}

tests/unit/s2n_timer_test.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@
1212
* express or implied. See the License for the specific language governing
1313
* permissions and limitations under the License.
1414
*/
15-
#include "s2n_test.h"
16-
1715
#include "utils/s2n_timer.h"
1816

17+
#include "s2n_test.h"
1918
#include "tls/s2n_config.h"
2019

21-
22-
2320
int mock_clock(void *in, uint64_t *out)
2421
{
25-
*out = *(uint64_t *)in;
22+
*out = *(uint64_t *) in;
2623

2724
return 0;
2825
}

tests/unit/s2n_tls12_handshake_test.c

+31-37
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
*/
1515

1616
#include "api/s2n.h"
17-
1817
#include "s2n_test.h"
1918
#include "testlib/s2n_testlib.h"
20-
2119
#include "tls/s2n_connection.h"
2220
#include "tls/s2n_handshake.h"
2321
#include "utils/s2n_safety.h"
@@ -30,19 +28,20 @@ static message_type_t invalid_handshake[S2N_MAX_HANDSHAKE_LENGTH] = { 0 };
3028
static int expected_handler_called;
3129
static int unexpected_handler_called;
3230

33-
static int s2n_test_handler(struct s2n_connection* conn)
31+
static int s2n_test_handler(struct s2n_connection *conn)
3432
{
3533
unexpected_handler_called = 1;
3634
return 0;
3735
}
3836

39-
static int s2n_test_expected_handler(struct s2n_connection* conn)
37+
static int s2n_test_expected_handler(struct s2n_connection *conn)
4038
{
4139
expected_handler_called = 1;
4240
return 0;
4341
}
4442

45-
static int s2n_setup_handler_to_expect(message_type_t expected, uint8_t direction) {
43+
static int s2n_setup_handler_to_expect(message_type_t expected, uint8_t direction)
44+
{
4645
for (int i = 0; i < s2n_array_len(state_machine); i++) {
4746
state_machine[i].handler[0] = s2n_test_handler;
4847
state_machine[i].handler[1] = s2n_test_handler;
@@ -96,7 +95,7 @@ int main(int argc, char **argv)
9695
uint16_t valid_tls12_handshakes[S2N_HANDSHAKES_COUNT];
9796
int valid_tls12_handshakes_size = 0;
9897
for (int i = 0; i < S2N_HANDSHAKES_COUNT; i++) {
99-
if(memcmp(handshakes[i], invalid_handshake, S2N_MAX_HANDSHAKE_LENGTH) != 0) {
98+
if (memcmp(handshakes[i], invalid_handshake, S2N_MAX_HANDSHAKE_LENGTH) != 0) {
10099
valid_tls12_handshakes[valid_tls12_handshakes_size] = i;
101100
valid_tls12_handshakes_size++;
102101
}
@@ -111,7 +110,7 @@ int main(int argc, char **argv)
111110
EXPECT_EQUAL(ACTIVE_STATE_MACHINE(conn), state_machine);
112111
EXPECT_EQUAL(ACTIVE_HANDSHAKES(conn), handshakes);
113112
EXPECT_SUCCESS(s2n_connection_free(conn));
114-
}
113+
};
115114

116115
/* Test: TLS1.2 server waits for expected CCS messages */
117116
{
@@ -138,7 +137,7 @@ int main(int argc, char **argv)
138137
}
139138

140139
EXPECT_SUCCESS(s2n_connection_free(conn));
141-
}
140+
};
142141

143142
/* Test: Client CCS messages always come before Client Finished messages */
144143
{
@@ -152,7 +151,6 @@ int main(int argc, char **argv)
152151
bool ccs_encountered = false;
153152

154153
for (int j = 0; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
155-
156154
if (handshakes[handshake][j] == CLIENT_CHANGE_CIPHER_SPEC) {
157155
ccs_encountered = true;
158156
}
@@ -164,7 +162,7 @@ int main(int argc, char **argv)
164162
/* Every valid handshake includes a CCS message */
165163
EXPECT_TRUE(ccs_encountered);
166164
}
167-
}
165+
};
168166

169167
/* Test: TLS1.2 client waits for expected CCS messages */
170168
{
@@ -191,7 +189,7 @@ int main(int argc, char **argv)
191189
}
192190

193191
EXPECT_SUCCESS(s2n_connection_free(conn));
194-
}
192+
};
195193

196194
/* Test: TLS1.2 client handles expected server CCS messages
197195
* but errors on unexpected CCS messages */
@@ -231,7 +229,7 @@ int main(int argc, char **argv)
231229

232230
EXPECT_SUCCESS(s2n_stuffer_free(&input));
233231
EXPECT_SUCCESS(s2n_connection_free(conn));
234-
}
232+
};
235233

236234
/* Test: TLS1.2 server handles expected client CCS messages
237235
* but errors on unexpected CCS messages */
@@ -271,7 +269,7 @@ int main(int argc, char **argv)
271269

272270
EXPECT_SUCCESS(s2n_stuffer_free(&input));
273271
EXPECT_SUCCESS(s2n_connection_free(conn));
274-
}
272+
};
275273

276274
/* Test: TLS1.2 client can receive a hello request message at any time. */
277275
{
@@ -305,7 +303,7 @@ int main(int argc, char **argv)
305303
EXPECT_FALSE(unexpected_handler_called);
306304
EXPECT_SUCCESS(s2n_stuffer_free(&input));
307305
EXPECT_SUCCESS(s2n_connection_free(conn));
308-
}
306+
};
309307

310308
/* Test: TLS1.2 s2n_handshake_read_io should accept only the expected message */
311309
{
@@ -332,7 +330,7 @@ int main(int argc, char **argv)
332330

333331
EXPECT_SUCCESS(s2n_stuffer_free(&input));
334332
EXPECT_SUCCESS(s2n_connection_free(conn));
335-
}
333+
};
336334

337335
/* TLS1.2 should error for an unexpected message */
338336
{
@@ -357,7 +355,7 @@ int main(int argc, char **argv)
357355

358356
EXPECT_SUCCESS(s2n_stuffer_free(&input));
359357
EXPECT_SUCCESS(s2n_connection_free(conn));
360-
}
358+
};
361359

362360
/* TLS1.2 should error for an expected message from the wrong writer */
363361
{
@@ -382,7 +380,7 @@ int main(int argc, char **argv)
382380

383381
EXPECT_SUCCESS(s2n_stuffer_free(&input));
384382
EXPECT_SUCCESS(s2n_connection_free(conn));
385-
}
383+
};
386384

387385
/* TLS1.2 should error for an expected message from the wrong record type */
388386
{
@@ -419,8 +417,8 @@ int main(int argc, char **argv)
419417
EXPECT_SUCCESS(s2n_stuffer_free(&input));
420418
EXPECT_SUCCESS(s2n_connection_free(conn));
421419
state_machine[SERVER_CHANGE_CIPHER_SPEC].message_type = old_message_type;
422-
}
423-
}
420+
};
421+
};
424422

425423
/* Test: TLS1.2 handshake type name maximum size is set correctly.
426424
* The maximum size is the size of a name with all flags set. */
@@ -433,7 +431,7 @@ int main(int argc, char **argv)
433431
fprintf(stderr, "\nMAX_HANDSHAKE_TYPE_LEN should be at least %lu\n", (unsigned long) correct_size);
434432
FAIL_MSG("MAX_HANDSHAKE_TYPE_LEN wrong for TLS1.2 handshakes");
435433
}
436-
}
434+
};
437435

438436
/* Test: TLS 1.2 handshake types are all properly printed */
439437
{
@@ -446,10 +444,9 @@ int main(int argc, char **argv)
446444
conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
447445
EXPECT_STRING_EQUAL("NEGOTIATED|FULL_HANDSHAKE", s2n_connection_get_handshake_type_name(conn));
448446

449-
const char* all_flags_handshake_type_name = "NEGOTIATED|FULL_HANDSHAKE|CLIENT_AUTH|NO_CLIENT_CERT|"
450-
"TLS12_PERFECT_FORWARD_SECRECY|OCSP_STATUS|WITH_SESSION_TICKET|WITH_NPN";
451-
conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE | CLIENT_AUTH | NO_CLIENT_CERT | \
452-
TLS12_PERFECT_FORWARD_SECRECY | OCSP_STATUS | WITH_SESSION_TICKET | WITH_NPN;
447+
const char *all_flags_handshake_type_name = "NEGOTIATED|FULL_HANDSHAKE|CLIENT_AUTH|NO_CLIENT_CERT|"
448+
"TLS12_PERFECT_FORWARD_SECRECY|OCSP_STATUS|WITH_SESSION_TICKET|WITH_NPN";
449+
conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE | CLIENT_AUTH | NO_CLIENT_CERT | TLS12_PERFECT_FORWARD_SECRECY | OCSP_STATUS | WITH_SESSION_TICKET | WITH_NPN;
453450
EXPECT_STRING_EQUAL(all_flags_handshake_type_name, s2n_connection_get_handshake_type_name(conn));
454451

455452
const char *handshake_type_name;
@@ -470,37 +467,35 @@ int main(int argc, char **argv)
470467
}
471468

472469
EXPECT_SUCCESS(s2n_connection_free(conn));
473-
}
470+
};
474471

475472
/* Test: TLS 1.2 message types are all properly printed */
476473
{
477-
uint32_t test_handshake_type = NEGOTIATED | FULL_HANDSHAKE | TLS12_PERFECT_FORWARD_SECRECY | \
478-
OCSP_STATUS | CLIENT_AUTH | WITH_SESSION_TICKET | WITH_NPN;
479-
const char* expected[] = { "CLIENT_HELLO",
480-
"SERVER_HELLO", "SERVER_CERT", "SERVER_CERT_STATUS", "SERVER_KEY", "SERVER_CERT_REQ", "SERVER_HELLO_DONE",
481-
"CLIENT_CERT", "CLIENT_KEY", "CLIENT_CERT_VERIFY", "CLIENT_CHANGE_CIPHER_SPEC", "CLIENT_NPN",
482-
"CLIENT_FINISHED", "SERVER_NEW_SESSION_TICKET", "SERVER_CHANGE_CIPHER_SPEC", "SERVER_FINISHED",
483-
"APPLICATION_DATA" };
474+
uint32_t test_handshake_type = NEGOTIATED | FULL_HANDSHAKE | TLS12_PERFECT_FORWARD_SECRECY | OCSP_STATUS | CLIENT_AUTH | WITH_SESSION_TICKET | WITH_NPN;
475+
const char *expected[] = { "CLIENT_HELLO",
476+
"SERVER_HELLO", "SERVER_CERT", "SERVER_CERT_STATUS", "SERVER_KEY", "SERVER_CERT_REQ", "SERVER_HELLO_DONE",
477+
"CLIENT_CERT", "CLIENT_KEY", "CLIENT_CERT_VERIFY", "CLIENT_CHANGE_CIPHER_SPEC", "CLIENT_NPN",
478+
"CLIENT_FINISHED", "SERVER_NEW_SESSION_TICKET", "SERVER_CHANGE_CIPHER_SPEC", "SERVER_FINISHED",
479+
"APPLICATION_DATA" };
484480

485481
struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
486482

487483
conn->handshake.handshake_type = test_handshake_type;
488484

489-
for (int i=0; i < sizeof(expected) / sizeof(char *); i++) {
485+
for (int i = 0; i < sizeof(expected) / sizeof(char *); i++) {
490486
conn->handshake.message_number = i;
491487
EXPECT_STRING_EQUAL(expected[i], s2n_connection_get_last_message_name(conn));
492488
}
493489

494490
EXPECT_SUCCESS(s2n_connection_free(conn));
495-
}
491+
};
496492

497493
/* Test: A WITH_NPN form of every valid, negotiated handshake exists */
498494
{
499495
uint32_t handshake_type_original, handshake_type_npn;
500496
message_type_t *messages_original, *messages_npn;
501497

502498
for (size_t i = 0; i < valid_tls12_handshakes_size; i++) {
503-
504499
handshake_type_original = valid_tls12_handshakes[i];
505500
messages_original = handshakes[handshake_type_original];
506501

@@ -514,7 +509,6 @@ int main(int argc, char **argv)
514509
messages_npn = handshakes[handshake_type_npn];
515510

516511
for (size_t j = 0, j_npn = 0; j < S2N_MAX_HANDSHAKE_LENGTH && j_npn < S2N_MAX_HANDSHAKE_LENGTH; j++, j_npn++) {
517-
518512
/* The original handshake cannot contain the Next Protocol message */
519513
EXPECT_NOT_EQUAL(messages_original[j], CLIENT_NPN);
520514

@@ -527,7 +521,7 @@ int main(int argc, char **argv)
527521
EXPECT_EQUAL(messages_original[j], messages_npn[j_npn]);
528522
}
529523
}
530-
}
524+
};
531525

532526
END_TEST();
533527
return 0;

tests/unit/s2n_tls13_cert_request_extensions_test.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
#include "s2n_test.h"
17-
18-
#include <string.h>
1916
#include <stdio.h>
20-
#include "api/s2n.h"
17+
#include <string.h>
2118

22-
#include "tls/extensions/s2n_server_supported_versions.h"
23-
#include "tls/extensions/s2n_server_signature_algorithms.h"
19+
#include "api/s2n.h"
20+
#include "s2n_test.h"
2421
#include "stuffer/s2n_stuffer.h"
2522
#include "testlib/s2n_testlib.h"
23+
#include "tls/extensions/s2n_server_signature_algorithms.h"
24+
#include "tls/extensions/s2n_server_supported_versions.h"
2625
#include "tls/s2n_tls.h"
2726
#include "tls/s2n_tls13.h"
2827
#include "utils/s2n_safety.h"
@@ -59,7 +58,7 @@ int main(int argc, char **argv)
5958
EXPECT_FAILURE_WITH_ERRNO(s2n_tls13_cert_req_recv(client_conn), S2N_ERR_MISSING_EXTENSION);
6059

6160
EXPECT_SUCCESS(s2n_connection_free(client_conn));
62-
}
61+
};
6362

6463
EXPECT_SUCCESS(s2n_disable_tls13_in_test());
6564
END_TEST();

tests/unit/s2n_tls13_cert_request_test.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
#include "s2n_test.h"
17-
18-
#include <string.h>
1916
#include <stdio.h>
20-
#include "api/s2n.h"
17+
#include <string.h>
2118

22-
#include "tls/extensions/s2n_server_signature_algorithms.h"
19+
#include "api/s2n.h"
20+
#include "s2n_test.h"
2321
#include "stuffer/s2n_stuffer.h"
2422
#include "testlib/s2n_testlib.h"
23+
#include "tls/extensions/s2n_server_signature_algorithms.h"
2524
#include "tls/s2n_tls.h"
2625
#include "tls/s2n_tls13.h"
2726
#include "utils/s2n_safety.h"
@@ -74,7 +73,7 @@ int main(int argc, char **argv)
7473

7574
EXPECT_SUCCESS(s2n_connection_free(client_conn));
7675
EXPECT_SUCCESS(s2n_connection_free(server_conn));
77-
}
76+
};
7877

7978
/* Test request context length other than 0 fails */
8079
{
@@ -91,7 +90,7 @@ int main(int argc, char **argv)
9190
EXPECT_FAILURE_WITH_ERRNO(s2n_tls13_cert_req_recv(client_conn), S2N_ERR_BAD_MESSAGE);
9291

9392
EXPECT_SUCCESS(s2n_connection_free(client_conn));
94-
}
93+
};
9594

9695
EXPECT_SUCCESS(s2n_disable_tls13_in_test());
9796
END_TEST();

0 commit comments

Comments
 (0)