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