libwbclient-tests: No longer hardcoded password and test domain
authorAndrew Bartlett <abartlet@samba.org>
Mon, 12 May 2014 02:29:27 +0000 (14:29 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 4 Jun 2014 01:22:26 +0000 (03:22 +0200)
The password is made more complex, and the test domain is made to
use the command line options.

Andrew Bartlett

Change-Id: Ia1ec24a9fc393e7f7b210f845bcf32dbc933d48f
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
nsswitch/libwbclient/tests/wbclient.c

index cd44d692628305ccb2076aec6c74425b25318776..771b848533c45add4ec05f82c83d391583b00f05 100644 (file)
@@ -31,6 +31,8 @@
 #include "lib/param/param.h"
 #include "lib/util/samba_util.h"
 #include "lib/crypto/arcfour.h"
+#include "auth/credentials/credentials.h"
+#include "lib/cmdline/popt_common.h"
 
 #define WBC_ERROR_EQUAL(x,y) (x == y)
 
@@ -464,12 +466,13 @@ static bool test_wbc_authenticate_user_int(struct torture_context *tctx,
        struct wbcAuthErrorInfo *error = NULL;
        wbcErr ret;
 
-       ret = wbcAuthenticateUser(getenv("USERNAME"), correct_password);
+       ret = wbcAuthenticateUser(cli_credentials_get_username(cmdline_credentials), correct_password);
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
-                                "wbcAuthenticateUser of %s failed", getenv("USERNAME"));
+                                "wbcAuthenticateUser of %s failed",
+                                cli_credentials_get_username(cmdline_credentials));
 
        ZERO_STRUCT(params);
-       params.account_name             = getenv("USERNAME");
+       params.account_name             = cli_credentials_get_username(cmdline_credentials);
        params.level                    = WBC_AUTH_USER_LEVEL_PLAIN;
        params.password.plaintext       = correct_password;
 
@@ -498,14 +501,14 @@ static bool test_wbc_authenticate_user_int(struct torture_context *tctx,
 
 static bool test_wbc_authenticate_user(struct torture_context *tctx)
 {
-       return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
+       return test_wbc_authenticate_user_int(tctx, cli_credentials_get_password(cmdline_credentials));
 }
 
 static bool test_wbc_change_password(struct torture_context *tctx)
 {
        wbcErr ret;
-       const char *oldpass = getenv("PASSWORD");
-       const char *newpass = "Koo8irei";
+       const char *oldpass = cli_credentials_get_password(cmdline_credentials);
+       const char *newpass = "Koo8irei%$";
 
        struct samr_CryptPassword new_nt_password;
        struct samr_CryptPassword new_lm_password;
@@ -569,23 +572,23 @@ static bool test_wbc_change_password(struct torture_context *tctx)
        params.new_password.response.nt_data = new_nt_password.data;
 
        params.level = WBC_CHANGE_PASSWORD_LEVEL_RESPONSE;
-       params.account_name = getenv("USERNAME");
-       params.domain_name = "SAMBA-TEST";
+       params.account_name = cli_credentials_get_username(cmdline_credentials);
+       params.domain_name = cli_credentials_get_domain(cmdline_credentials);
 
        ret = wbcChangeUserPasswordEx(&params, NULL, NULL, NULL);
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
                                 "wbcChangeUserPassword for %s failed", params.account_name);
 
-       if (!test_wbc_authenticate_user_int(tctx, "Koo8irei")) {
+       if (!test_wbc_authenticate_user_int(tctx, newpass)) {
                return false;
        }
 
-       ret = wbcChangeUserPassword(getenv("USERNAME"), "Koo8irei",
-                                   getenv("PASSWORD"));
+       ret = wbcChangeUserPassword(cli_credentials_get_username(cmdline_credentials), newpass,
+                                   cli_credentials_get_password(cmdline_credentials));
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
                                 "wbcChangeUserPassword for %s failed", params.account_name);
 
-       return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
+       return test_wbc_authenticate_user_int(tctx, cli_credentials_get_password(cmdline_credentials));
 }
 
 static bool test_wbc_logon_user(struct torture_context *tctx)
@@ -607,8 +610,8 @@ static bool test_wbc_logon_user(struct torture_context *tctx)
                                 "%s", "wbcLogonUser succeeded for NULL where it should "
                                 "have failed");
 
-       params.username = getenv("USERNAME");
-       params.password = getenv("PASSWORD");
+       params.username = cli_credentials_get_username(cmdline_credentials);
+       params.password = cli_credentials_get_password(cmdline_credentials);
 
        ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
                              "foo", 0, discard_const_p(uint8_t, "bar"), 4);
@@ -638,7 +641,7 @@ static bool test_wbc_logon_user(struct torture_context *tctx)
                              strlen("S-1-2-3-4")+1);
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
                                 "%s", "wbcAddNamedBlob failed");
-       params.password = getenv("PASSWORD");
+       params.password = cli_credentials_get_password(cmdline_credentials);
        ret = wbcLogonUser(&params, &info, &error, &policy);
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
                                 "wbcLogonUser for %s should have failed with "
@@ -653,11 +656,11 @@ static bool test_wbc_logon_user(struct torture_context *tctx)
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
                                 "%s", "wbcInterfaceDetails failed");
 
-       ret = wbcLookupName(iface->netbios_domain, getenv("USERNAME"), &sid,
+       ret = wbcLookupName(iface->netbios_domain, cli_credentials_get_username(cmdline_credentials), &sid,
                            &sidtype);
        wbcFreeMemory(iface);
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
-                                "wbcLookupName for %s failed", getenv("USERNAME"));
+                                "wbcLookupName for %s failed", cli_credentials_get_username(cmdline_credentials));
 
        ret = wbcSidToString(&sid, &sidstr);
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
@@ -669,7 +672,7 @@ static bool test_wbc_logon_user(struct torture_context *tctx)
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
                                 "%s", "wbcAddNamedBlob failed");
        wbcFreeMemory(sidstr);
-       params.password = getenv("PASSWORD");
+       params.password = cli_credentials_get_password(cmdline_credentials);
        ret = wbcLogonUser(&params, &info, &error, &policy);
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
                                 "wbcLogonUser for %s failed", params.username);
@@ -688,9 +691,9 @@ static bool test_wbc_getgroups(struct torture_context *tctx)
        uint32_t num_groups;
        gid_t *groups;
 
-       ret = wbcGetGroups(getenv("USERNAME"), &num_groups, &groups);
+       ret = wbcGetGroups(cli_credentials_get_username(cmdline_credentials), &num_groups, &groups);
        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
-                                "wbcGetGroups for %s failed", getenv("USERNAME"));
+                                "wbcGetGroups for %s failed", cli_credentials_get_username(cmdline_credentials));
        wbcFreeMemory(groups);
        return true;
 }