b6b438
From fe1f6278c7a5c54d948f6ca031686745ad653a94 Mon Sep 17 00:00:00 2001
b6b438
From: Andreas Schneider <asn@samba.org>
b6b438
Date: Tue, 9 Jul 2019 13:06:49 +0200
b6b438
Subject: [PATCH 018/187] libcli:auth: Add test for encode_rc4_passwd_buffer()
b6b438
b6b438
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14031
b6b438
b6b438
Signed-off-by: Andreas Schneider <asn@samba.org>
b6b438
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
b6b438
(cherry picked from commit fe00b3735a7e8ae16fb6443965769f1e947a6aa6)
b6b438
---
b6b438
 libcli/auth/tests/test_rc4_passwd_buffer.c | 31 ++++++++++++++++++++++
b6b438
 1 file changed, 31 insertions(+)
b6b438
b6b438
diff --git a/libcli/auth/tests/test_rc4_passwd_buffer.c b/libcli/auth/tests/test_rc4_passwd_buffer.c
b6b438
index 3bf371c5dd5..db6ca3f3f4c 100644
b6b438
--- a/libcli/auth/tests/test_rc4_passwd_buffer.c
b6b438
+++ b/libcli/auth/tests/test_rc4_passwd_buffer.c
b6b438
@@ -157,12 +157,43 @@ static void torture_rc4_passwd_buffer(void **state)
b6b438
 	talloc_free(password_decoded);
b6b438
 }
b6b438
 
b6b438
+static void torture_endode_decode_rc4_passwd_buffer(void **state)
b6b438
+{
b6b438
+	char *password_decoded = NULL;
b6b438
+	size_t password_decoded_len = 0;
b6b438
+	DATA_BLOB session_key = data_blob_const("SystemLibraryDTC", 16);
b6b438
+	struct samr_CryptPasswordEx out_pwd_buf = {
b6b438
+		.data = {0},
b6b438
+	};
b6b438
+	NTSTATUS status;
b6b438
+	bool ok;
b6b438
+
b6b438
+	status = encode_rc4_passwd_buffer(PASSWORD,
b6b438
+					  &session_key,
b6b438
+					  &out_pwd_buf);
b6b438
+	assert_true(NT_STATUS_IS_OK(status));
b6b438
+
b6b438
+	status = decode_rc4_passwd_buffer(&session_key, &out_pwd_buf);
b6b438
+	assert_true(NT_STATUS_IS_OK(status));
b6b438
+
b6b438
+	ok = decode_pw_buffer(NULL,
b6b438
+			      out_pwd_buf.data,
b6b438
+			      &password_decoded,
b6b438
+			      &password_decoded_len,
b6b438
+			      CH_UTF16);
b6b438
+	assert_true(ok);
b6b438
+	assert_int_equal(password_decoded_len, strlen(PASSWORD));
b6b438
+	assert_string_equal(password_decoded, PASSWORD);
b6b438
+	talloc_free(password_decoded);
b6b438
+}
b6b438
+
b6b438
 int main(int argc, char *argv[])
b6b438
 {
b6b438
 	int rc;
b6b438
 	const struct CMUnitTest tests[] = {
b6b438
 		cmocka_unit_test(torture_decode_rc4_passwd_buffer),
b6b438
 		cmocka_unit_test(torture_rc4_passwd_buffer),
b6b438
+		cmocka_unit_test(torture_endode_decode_rc4_passwd_buffer),
b6b438
 	};
b6b438
 
b6b438
 	if (argc == 2) {
b6b438
-- 
b6b438
2.23.0
b6b438