summaryrefslogtreecommitdiff
path: root/tests/core
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-11-18 10:29:07 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2018-11-28 15:46:57 +0000
commitdf2cc1087f6de8718319e5bcc65ca8e0e07b717e (patch)
tree02264b646329a5eeca8940fa8557e714e303a50f /tests/core
parent0467606ff4dbf57401c8b58188652df821ec865b (diff)
downloadlibgit2-df2cc1087f6de8718319e5bcc65ca8e0e07b717e.tar.gz
stream: provide generic registration API
Update the new stream registration API to be `git_stream_register` which takes a registration structure and a TLS boolean. This allows callers to register non-TLS streams as well as TLS streams. Provide `git_stream_register_tls` that takes just the init callback for backward compatibliity.
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/stream.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/tests/core/stream.c b/tests/core/stream.c
index 872571f39..a76169d48 100644
--- a/tests/core/stream.c
+++ b/tests/core/stream.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "git2/sys/stream.h"
#include "streams/tls.h"
+#include "streams/socket.h"
#include "stream.h"
static git_stream test_stream;
@@ -28,6 +29,32 @@ static int test_stream_wrap(git_stream **out, git_stream *in, const char *host)
return 0;
}
+void test_core_stream__register_insecure(void)
+{
+ git_stream *stream;
+ git_stream_registration registration = {0};
+
+ registration.version = 1;
+ registration.init = test_stream_init;
+ registration.wrap = test_stream_wrap;
+
+ ctor_called = 0;
+ cl_git_pass(git_stream_register(0, &registration));
+ cl_git_pass(git_socket_stream_new(&stream, "localhost", "80"));
+ cl_assert_equal_i(1, ctor_called);
+ cl_assert_equal_p(&test_stream, stream);
+
+ ctor_called = 0;
+ stream = NULL;
+ cl_git_pass(git_stream_register(0, NULL));
+ cl_git_pass(git_socket_stream_new(&stream, "localhost", "80"));
+
+ cl_assert_equal_i(0, ctor_called);
+ cl_assert(&test_stream != stream);
+
+ git_stream_free(stream);
+}
+
void test_core_stream__register_tls(void)
{
git_stream *stream;
@@ -39,14 +66,14 @@ void test_core_stream__register_tls(void)
registration.wrap = test_stream_wrap;
ctor_called = 0;
- cl_git_pass(git_stream_register_tls(&registration));
+ cl_git_pass(git_stream_register(1, &registration));
cl_git_pass(git_tls_stream_new(&stream, "localhost", "443"));
cl_assert_equal_i(1, ctor_called);
cl_assert_equal_p(&test_stream, stream);
ctor_called = 0;
stream = NULL;
- cl_git_pass(git_stream_register_tls(NULL));
+ cl_git_pass(git_stream_register(1, NULL));
error = git_tls_stream_new(&stream, "localhost", "443");
/* We don't have TLS support enabled, or we're on Windows,
@@ -63,3 +90,35 @@ void test_core_stream__register_tls(void)
git_stream_free(stream);
}
+
+void test_core_stream__register_tls_deprecated(void)
+{
+ git_stream *stream;
+ int error;
+
+ ctor_called = 0;
+ cl_git_pass(git_stream_register_tls(test_stream_init));
+ cl_git_pass(git_tls_stream_new(&stream, "localhost", "443"));
+ cl_assert_equal_i(1, ctor_called);
+ cl_assert_equal_p(&test_stream, stream);
+
+ ctor_called = 0;
+ stream = NULL;
+ cl_git_pass(git_stream_register_tls(NULL));
+ error = git_tls_stream_new(&stream, "localhost", "443");
+
+ /*
+ * We don't have TLS support enabled, or we're on Windows,
+ * which has no arbitrary TLS stream support.
+ */
+#if defined(GIT_WIN32) || !defined(GIT_HTTPS)
+ cl_git_fail_with(-1, error);
+#else
+ cl_git_pass(error);
+#endif
+
+ cl_assert_equal_i(0, ctor_called);
+ cl_assert(&test_stream != stream);
+
+ git_stream_free(stream);
+}