Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix open AF_INET sockets in s2n_self_talk_ktls_test.c #4852

Merged
merged 9 commits into from
Nov 12, 2024
19 changes: 12 additions & 7 deletions tests/unit/s2n_self_talk_ktls_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ static S2N_RESULT s2n_new_inet_socket_pair(struct s2n_test_io_pair *io_pair)
RESULT_ENSURE_GTE(pid, 0);
if (pid == 0) {
RESULT_ENSURE_EQ(connect(io_pair->client, (struct sockaddr *) &saddr, addrlen), 0);
ZERO_TO_DISABLE_DEFER_CLEANUP(io_pair);
EXPECT_SUCCESS(s2n_io_pair_close(io_pair));
RESULT_ENSURE_EQ(close(listener), 0);
exit(0);
}
io_pair->server = accept(listener, NULL, NULL);
RESULT_ENSURE_GT(io_pair->server, 0);
RESULT_ENSURE_EQ(close(listener), 0);
return S2N_RESULT_OK;
}

Expand Down Expand Up @@ -134,12 +136,6 @@ int main(int argc, char **argv)
sizeof(test_data),
};

uint8_t file_test_data[100] = { 0 };
int file = open(argv[0], O_RDONLY);
EXPECT_TRUE(file > 0);
int file_read = pread(file, file_test_data, sizeof(file_test_data), 0);
EXPECT_EQUAL(file_read, sizeof(file_test_data));

DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config));
Expand Down Expand Up @@ -171,6 +167,7 @@ int main(int argc, char **argv)
* to be able to test ktls.
*/
EXPECT_FALSE(ktls_expected);
EXPECT_SUCCESS(s2n_io_pair_close(&io_pair));
END_TEST();
}
EXPECT_OK(s2n_setup_connections(server, client, &io_pair));
Expand Down Expand Up @@ -270,6 +267,12 @@ int main(int argc, char **argv)
};

/* Test: s2n_sendfile */
uint8_t file_test_data[100] = { 0 };
int file = open(argv[0], O_RDONLY);
EXPECT_TRUE(file > 0);
int file_read = pread(file, file_test_data, sizeof(file_test_data), 0);
EXPECT_EQUAL(file_read, sizeof(file_test_data));

for (size_t offset_i = 0; offset_i < s2n_array_len(test_offsets); offset_i++) {
const size_t offset = test_offsets[offset_i];
const size_t expected_written = sizeof(test_data) - offset;
Expand All @@ -288,6 +291,8 @@ int main(int argc, char **argv)
EXPECT_BYTEARRAY_EQUAL(file_test_data + offset, buffer, read);
}

EXPECT_SUCCESS(close(file));
boquan-fang marked this conversation as resolved.
Show resolved Hide resolved

/* Test: s2n_shutdown */
{
EXPECT_SUCCESS(s2n_shutdown_send(writer, &blocked));
Expand Down
Loading