1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-31 00:03:08 +03:00
Files
libssh2/tests/test_public_key_auth_fails_with_wrong_key.c
Alexander Lamaison cf80f2f4b5 Basic dockerised test suite.
This introduces a test suite for libssh2. It runs OpenSSH in a Docker
container because that works well on Windows (via docker-machine) as
well as Linux. Presumably it works on Mac too with docker-machine, but
I've not tested that.

Because the test suite is docker-machine aware, you can also run it
against a cloud provider, for more realistic network testing, by setting
your cloud provider as your active docker machine. The Appveyor CI setup
in this commit does that because Appveyor doesn't support docker
locally.
2016-08-14 16:03:25 +01:00

38 lines
965 B
C

#include "session_fixture.h"
#include <libssh2.h>
#include <stdio.h>
const char *USERNAME = "libssh2"; /* configured in Dockerfile */
const char *KEY_FILE_PRIVATE = "key_dsa_wrong";
const char *KEY_FILE_PUBLIC = "key_dsa_wrong.pub";
int test(LIBSSH2_SESSION *session)
{
int rc;
const char *userauth_list =
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
if (userauth_list == NULL) {
print_last_session_error("libssh2_userauth_list");
return 1;
}
if (strstr(userauth_list, "publickey") == NULL) {
fprintf(stderr, "'publickey' was expected in userauth list: %s\n",
userauth_list);
return 1;
}
rc = libssh2_userauth_publickey_fromfile_ex(
session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE,
NULL);
if (rc == 0) {
fprintf(stderr, "Public-key auth succeeded with wrong key\n");
return 1;
}
return 0;
}