protected void btnTest_Click(object sender, EventArgs e) { string returnValue; t = Token.Request_WithTenantID("http://198.61.199.47:35357/", "admin", "password", "tenant1"); //Create User u = Trinity.OpenStack.User.Add("http://198.61.199.47:35357", "Bill", "Bob", "True", "123", "*****@*****.**", t.token_id); lblAddUsername.Text = "Username: "******"Email: " + u.email; lblAddEnabled.Text = "Enabled: " + u.enabled; //Successful Update Trinity.OpenStack.User.Update(t.token_id, u.id, "Billy", "*****@*****.**", "False", u.tenantid, "http://198.61.199.47:35357"); lblUpdateUsername.Text = "Username: Billy"; lblUpdateEmail.Text = "Email: [email protected]"; lblUpdateEnabled.Text = "Enabled: False"; //Invalid Admin Token returnValue = Trinity.OpenStack.User.Update("123", u.id, "Billy", "*****@*****.**", "False", u.tenantid, "http://198.61.199.47:35357"); lblAdminToken.Text = returnValue; //Invalid User ID returnValue = Trinity.OpenStack.User.Update(t.token_id, "321", "Billy", "*****@*****.**", "False", u.tenantid, "http://198.61.199.47:35357"); lblUserID.Text = returnValue; //Invalid TenantID returnValue = Trinity.OpenStack.User.Update(t.token_id, u.id, "Billy", "*****@*****.**", "False", "451", "http://198.61.199.47:35357"); lblTenantID.Text = returnValue; //Invalid URL returnValue = Trinity.OpenStack.User.Update(t.token_id, u.id, "Billy", "*****@*****.**", "False", u.tenantid, "http://198.61.199.48:35357"); lblURL.Text = returnValue; //Delete User string deleteRet = Trinity.OpenStack.User.Delete("http://198.61.199.47:35357", u.id, t.token_id); lblDeleteUser.Text = deleteRet; }
protected void btnNext3_Click(object sender, EventArgs e) { Panel4.Visible = true; string getuser_url = txtURL.Text + ":35357"; try { Trinity.OpenStack.User returned_user = new Trinity.OpenStack.User(); returned_user = Trinity.OpenStack.User.GetUserById(getuser_url, txtToken.Text, txtUserId.Text); txtGetResult.Text = ""; txtGetResult.Text += " Name: " + returned_user.name; txtGetResult.Text += Environment.NewLine; txtGetResult.Text += (" Enabled: " + returned_user.enabled); txtGetResult.Text += Environment.NewLine; txtGetResult.Text += (" Email: " + returned_user.email); txtGetResult.Text += Environment.NewLine; txtGetResult.Text += (" UserId: " + returned_user.id); txtGetResult.Text += Environment.NewLine; txtGetResult.Text += (" TenantId: " + returned_user.tenantid); txtGetResult.Text += Environment.NewLine; } catch (Exception x) { txtGetResult.Text = x.Message.ToString(); } }
protected void btnNext3_Click(object sender, EventArgs e) { Panel4.Visible = true; string updateuser_url = txtURL.Text + ":35357"; try { Trinity.OpenStack.User newuser = new Trinity.OpenStack.User(); newuser = Trinity.OpenStack.User.Update(txtToken.Text, txtUserId.Text, txtUserId.Text, txtName.Text, txtEmail.Text, txtUpdateEnable.Text, txtTenantId.Text, updateuser_url); txtUpdateResult.Text = "Updated User Infomation"; txtUpdateResult.Text += Environment.NewLine; txtUpdateResult.Text += ("================================================="); txtUpdateResult.Text += Environment.NewLine; txtUpdateResult.Text += " Name: " + newuser.name; txtUpdateResult.Text += Environment.NewLine; txtUpdateResult.Text += (" Enabled: " + newuser.enabled); txtUpdateResult.Text += Environment.NewLine; txtUpdateResult.Text += (" Email: " + newuser.email); txtUpdateResult.Text += Environment.NewLine; txtUpdateResult.Text += (" UserId: " + newuser.id); txtUpdateResult.Text += Environment.NewLine; txtUpdateResult.Text += (" TenantId: " + newuser.tenantid); txtUpdateResult.Text += Environment.NewLine; txtUpdateResult.Text += ("================================================="); txtUpdateResult.Text += Environment.NewLine; txtUpdateResult.Text += Environment.NewLine; } catch (Exception x) { txtUpdateResult.Text = x.Message.ToString(); } }
protected void btnTest1_Click(object sender, EventArgs e) { updatesList = new List<User>(); try { lblCreateUserPassFail.Visible = userUpdateTest.setUp(LoginSession.adminURL, LoginSession.userToken.token_id, "tstUserTen_1", "tstUserTen_2"); lblCreateUserPassFail.Text = "PASS"; lstbxUsers.Items.Clear(); Boolean ret = true; String output = String.Empty; before = userUpdateTest.getTestUser(); //End Set Up ret |= userUpdateTest.run(LoginSession.adminURL, LoginSession.userToken.token_id, userUpdateTest.updateTestUser.id, "updatedUsername1", "null", "true", userUpdateTest.testTenantId); updatesList.Add(userUpdateTest.getTestUser()); ret |= userUpdateTest.run(LoginSession.adminURL, LoginSession.userToken.token_id, userUpdateTest.updateTestUser.id, "updatedUsername1", "*****@*****.**", "true", userUpdateTest.testTenantId); updatesList.Add(userUpdateTest.getTestUser()); ret |= userUpdateTest.run(LoginSession.adminURL, LoginSession.userToken.token_id, userUpdateTest.updateTestUser.id, "updatedUsername1", "*****@*****.**", "true", userUpdateTest.testTenantId2); updatesList.Add(userUpdateTest.getTestUser()); ret |= userUpdateTest.run(LoginSession.adminURL, LoginSession.userToken.token_id, userUpdateTest.updateTestUser.id, "updatedUsername2", "*****@*****.**", "true", userUpdateTest.testTenantId2); updatesList.Add(userUpdateTest.getTestUser()); lblRunTest1.Visible = ret; lblRunTest1.Text = "PASS"; lstbxUsers.Items.Add(before.name + " " + before.id); lstbxAfter.Items.Clear(); try { lblTearDown1.Visible = userUpdateTest.tearDown(LoginSession.adminURL, LoginSession.userToken.token_id); lblTearDown1.Text = "PASS"; foreach (User u in updatesList) { lstbxAfter.Items.Add(u.name + " " + u.id); } } catch (Exception x) { lblUser.Text = x.Message; lblCreateUserPassFail.Visible = true; lblCreateUserPassFail.Text = "FAIL"; } } //End Run Test catch (Exception x) { lblUser.Text = x.Message; lblCreateUserPassFail.Visible = true; lblCreateUserPassFail.Text = "FAIL"; pnlUserInfo.Visible = true; } }
public static string PrettyPrint(User u) { string ret = string.Empty; ret = "{" + '\n' + "Name: " + u.name + '\n' + "Id: " + u.id + '\n' + "Email: " + u.email + '\n' + "Enabled: " + u.enabled + '\n' + "Tenant ID: " + u.tenantid + '\n' + "}" + "\n\n"; return ret; }
protected void btnNext3_Click(object sender, EventArgs e) { Panel4.Visible = true; Trinity.OpenStack.User returned_user = new Trinity.OpenStack.User(); try { string password_url = Session["stack_url"].ToString() + ":35357"; returned_user = Trinity.OpenStack.User.Update_Password(password_url, txtToken.Text, txtUserId.Text, txtName.Text, txtPassword.Text); txtUpdatePasswordResult.Text += Environment.NewLine; txtUpdatePasswordResult.Text += "Password Updated"; } catch (Exception x) { txtUpdatePasswordResult.Text = x.Message.ToString(); } }
protected void btnTest_Click(object sender, EventArgs e) { string url = "http://198.61.199.47:35357/"; t = Token.Request_WithTenantID(url, "admin", "password", "tenant1"); //List Users lblFirstListCall.Text = Trinity.OpenStack.User.List(url, t.token_id); //Add Quincy1 u = Trinity.OpenStack.User.Add(url, "Quincy1", "password", true.ToString(), "78f0f0f79cd241a2b6ade773f9ad5cf1", "*****@*****.**", t.token_id); lblAddQuincy.Text = u.name + " added."; //List Users again with Quincy1 this time lblSecondListCall.Text = Trinity.OpenStack.User.List(url, t.token_id); //Delete Quincy1 lblDeleteQuincy.Text = Trinity.OpenStack.User.Delete(url, u.id, t.token_id); //List Users again without Quincy1 this time lblThirdListCall.Text = Trinity.OpenStack.User.List(url, t.token_id); //Try to call list with an invalid URL lblURL.Text = Trinity.OpenStack.User.List("http://198.61.199.48:35357/", t.token_id); //Try to call list with an invalid admin_token lblAdminToken.Text = Trinity.OpenStack.User.List(url, "1234"); }
protected void btnTest1_Click(object sender, EventArgs e) { user = new User(); userGetTest = new TestGetUser(); try { lblCreateUserPassFail.Visible = userGetTest.setUp(LoginSession.adminURL, LoginSession.userToken.token_id, "tstUserTen_1"); lblCreateUserPassFail.Text = "PASS"; lstbxUser.Items.Clear(); user = userGetTest.user; lblRunTest1.Visible = userGetTest.run(LoginSession.adminURL, LoginSession.userToken.token_id, userGetTest.getTestUser.id); lblRunTest1.Text = "PASS"; user = userGetTest.user; lstbxUser.Items.Add(user.name); try { lblTearDown1.Visible = userGetTest.tearDown(LoginSession.adminURL, LoginSession.userToken.token_id); lblTearDown1.Text = "PASS"; } catch (Exception x) { lblUser.Text = x.Message; lblCreateUserPassFail.Visible = true; lblCreateUserPassFail.Text = "FAIL"; } } catch (Exception x) { lblUser.Text = x.Message; lblCreateUserPassFail.Visible = true; lblCreateUserPassFail.Text = "FAIL"; pnlUserInfo.Visible = true; } }
public Boolean setUp(string admin_url, string admin_token, string testTenantName, string testTenantName2) { try { Create_Test_Tenant(testTenantName, admin_url, admin_token, ref testTenantId); Create_Test_Tenant(testTenantName2, admin_url, admin_token, ref testTenantId2); try { string testUserName = "******"; string testUserPass = "******"; updateTestUserName = testUserName; updateTestUser = User.Add(admin_url, testUserName, testUserPass, "true", testTenantId, "null", admin_token); updates = new List<User>(); updateTestUserName = updateTestUser.name; testUserID = updateTestUser.id; } catch (Exception x) { try { tearDown(admin_url, admin_token); } catch { Delete_Test_Tenant(admin_url, admin_token, testTenantId); Delete_Test_Tenant(admin_url, admin_token, testTenantId2); } throw x; } } catch (Exception x) { throw x; } return true; }
public Boolean run(string admin_url, string admin_token, string userID, string username, string email, string enabled, string tenantID) { User update = new User(); update.name = updateTestUser.name; update.id = updateTestUser.id; update.email = updateTestUser.email; update.enabled = updateTestUser.enabled; update.tenantid = updateTestUser.tenantid; update.password = updateTestUser.password; try { bool eq = testUserID == updateTestUser.id; update = User.Update(admin_token, userID, userID, username, email, enabled, tenantID, admin_url); updateTestUser = User.GetUserById(admin_url, admin_token, userID); return compareUpdateAndNew(update); } catch (Exception x) { tearDown(admin_url, admin_token); throw x; } }
protected void Page_Load(object sender, EventArgs e) { TextBox1.Enabled = false; TextBox2.Enabled = false; TextBox3.Enabled = false; if (sender != null && sender.GetType().Equals(this.GetType())) { if (((UsersUpdate)sender).CurrentTest != null) { userUpdateTest = ((UsersUpdate)sender).CurrentTest; before = ((UsersUpdate)sender).beforeTest; updatesList = ((UsersUpdate)sender).updatesTestList; } else { userUpdateTest = new TestUpdateUser(); before = new User(); updatesList = new List<User>(); } } else { userUpdateTest = new TestUpdateUser(); before = new User(); updatesList = new List<User>(); } }
//==============================================================================// // // Parse Stack User JSON return // // //==============================================================================// public static User Parse(string server_return) { User return_user = new User(); try { //parse server return JObject oServerReturn = JObject.Parse(server_return); String userStr = oServerReturn["user"].ToString(); JObject oUserString = JObject.Parse(userStr); String user_name = oUserString["name"].ToString(); String user_email = oUserString["email"].ToString(); String user_tenantid = oUserString["tenantId"].ToString(); String user_id = oUserString["id"].ToString(); String user_enabled = oUserString["enabled"].ToString(); return_user.name = user_name; return_user.email = user_email; return_user.tenantid = user_tenantid; return_user.id = user_id; return_user.enabled = user_enabled; return return_user; } catch { return null; } }
public Boolean Tear_Down_Delete_Endpoints_Test(string admin_url, string admin_token, User u, string testServiceId, string testTenantId) { try { while (DisposableEndpoints.Count > 0) { DisposableEndpoints[0].Delete_Endpoint(admin_url, admin_token); DisposableEndpoints.RemoveAt(0); } } catch { //do nothing } Boolean ret = true; User.Delete(admin_url, u.id, admin_token); ret |= Delete_Test_Service(testServiceId, admin_url + "/v2.0/", admin_token); ret |= Delete_Test_Tenant(testTenantId, admin_url + "/v2.0/", admin_token); if (ret == true) { endpoint_testServiceid = String.Empty; endpoint_testTenantid = String.Empty; } return ret; }
//==============================================================================// // // Update User // // //==============================================================================// public static string Update(string admin_token,string NewID, string UserName, string Email, string Enabled, string TenantID, string url) { string ret = string.Empty; User parsed_user = new User(); string postData = "{ " + "\"user\": { " + "\"id\": \"" + NewID + "\"," + "\"name\": \"" + UserName + "\"," + "\"email\": \"" + Email + "\"," + "\"enabled\":" + Enabled + "," + "\"tenantId\":\"" + TenantID + "\"" + "}" + "}"; StreamWriter requestWriter; try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "PUT"; webRequest.Headers.Add("X-Auth-Token", admin_token); webRequest.ServicePoint.Expect100Continue = false; webRequest.Timeout = 1000; webRequest.ContentType = "application/json"; requestWriter = new StreamWriter(webRequest.GetRequestStream()); requestWriter.Write(postData); requestWriter.Close(); HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); Stream resStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(resStream); ret = reader.ReadToEnd(); parsed_user = User.Parse(ret); return(ret); } catch (Exception x) { return("Update failed: " + x.ToString()); } }
//==============================================================================// // // Get User by ID // // //==============================================================================// public static User Get_User_ID(string url, string AdminID) { User return_user = new User(); string ret = string.Empty; try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "GET"; webRequest.ServicePoint.Expect100Continue = false; webRequest.Headers.Add("X-Auth-Token", AdminID); webRequest.Timeout = 2000; HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); Stream resStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(resStream); ret = reader.ReadToEnd(); return_user = User.Parse(ret); return return_user; } catch (Exception x) { return_user.enabled = x.ToString(); return return_user; } }
//==============================================================================// // // Add User // // //==============================================================================// public static User Add(string url, string name, string password, string enabled, string tenantId, string email, string admin_token) { User return_user = new User(); string ret = string.Empty; StreamWriter requestWriter; String postData = "{" + "\"user\": {" + "\"name\": \"" + name + "\", " + "\"password\": \"" + password + "\"," + "\"email\": \"" + email + "\"," + "\"tenantId\": \"" + tenantId + "\"," + "\"enabled\": " + enabled + "}}"; try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Headers.Add("X-Auth-Token", admin_token); webRequest.Method = "POST"; webRequest.ServicePoint.Expect100Continue = false; webRequest.Timeout = 2000; webRequest.ContentType = "application/json"; requestWriter = new StreamWriter(webRequest.GetRequestStream()); requestWriter.Write(postData); requestWriter.Close(); HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); Stream resStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(resStream); ret = reader.ReadToEnd(); //parse server return ------------------------------------ JObject oServerReturn = JObject.Parse(ret); String userStr = oServerReturn["user"].ToString(); JObject oUserString = JObject.Parse(userStr); String user_name = oUserString["name"].ToString(); String user_email = oUserString["email"].ToString(); String user_tenantid = oUserString["tenantId"].ToString(); String user_id = oUserString["id"].ToString(); String user_enabled = oUserString["enabled"].ToString(); String user_password = oUserString["password"].ToString(); return_user.name = user_name; return_user.email = user_email; return_user.tenantid = user_tenantid; return_user.id = user_id; return_user.enabled = user_enabled; return_user.password = user_password; //-------------------------------------------------------- return (return_user); } catch (Exception x) { return_user.name = x.ToString(); return (return_user); } }
public Boolean setUp(string admin_url, string admin_token, string testTenantName) { try { Create_Test_Tenant(testTenantId, admin_url, admin_token, ref testTenantId); try { roleTestUser = User.Add(admin_url, "roleTestUser", "password", "true", testTenantId, "*****@*****.**", admin_token); return true; } catch (Exception x) { Delete_Test_Tenant(admin_url, admin_token, testTenantId); throw x; } } catch (Exception x) { throw x; } }
//==============================================================================// // // Add User // // //==============================================================================// public static User Add(string url, string name, string password, string enabled, string tenantId, string email, string admin_token) { User return_user = new User(); string ret = string.Empty; string adduser_url = url + "/v2.0/users"; StreamWriter requestWriter; String postData = "{" + "\"user\": {" + "\"name\": \"" + name + "\", " + "\"password\": \"" + password + "\"," + "\"email\": \"" + email + "\"," + "\"tenantId\": \"" + tenantId + "\"," + "\"enabled\": " + enabled + "}}"; try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(adduser_url); webRequest.Headers.Add("X-Auth-Token", admin_token); webRequest.Method = "POST"; webRequest.ServicePoint.Expect100Continue = false; webRequest.Timeout = 2000; webRequest.ContentType = "application/json"; requestWriter = new StreamWriter(webRequest.GetRequestStream()); requestWriter.Write(postData); requestWriter.Close(); HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); Stream resStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(resStream); ret = reader.ReadToEnd(); //parse server return ------------------------------------ try { return Parse(ret); } catch { throw new System.ArgumentException("String for JSON Parse had incorrect syntax"); } //-------------------------------------------------------- return (return_user); } catch (Exception x) { throw OpenStackObject.Parse_Error(x); } }
public Boolean Set_Up_Delete_Endpoints_Test(string admin_url, string admin_token, string testTenantName, string testServiceName) { Boolean ret = true; string admin_url2 = admin_url + "/v2.0/"; DisposableEndpoints = new List<Endpoint>(); string testTenantId = String.Empty; string testUserName = "******"; string testUserPw = "eptu123"; string testServiceId = String.Empty; try { Create_Test_Tenant(ref testTenantId, testTenantName, admin_url2, admin_token); //Create Tenant endpoint_testTenantid = testTenantId; try { Create_Test_Service(ref testServiceId, testServiceName, admin_url2, admin_token); //Create Service endpoint_testServiceid = testServiceId; User u = new User(); try { u = User.Add(admin_url, testUserName, testUserPw, "true", testTenantId, "null", admin_token); endpoint_testUser = u; EPTestToken = Token.Request_NoTenant(admin_url, testUserName, testUserPw); if (EPTestToken.token_error.Equals(String.Empty)) { em = new List<Endpoint>(); em = Endpoint.List_Endpoints(admin_url, admin_token, admin_token); BaseCount = em.Count; try { for (int i = 0; i < 10; i++) { Endpoint ep = Endpoint.Create_Endpoint(admin_token, admin_token, admin_url, testServiceId, "testDeleteEndpoint111213_" + i, testServiceId, admin_url + ":5000", admin_url + ":5000", testTenantId); DisposableEndpoints.Add(ep); } } catch (Exception x) { Tear_Down_Delete_Endpoints_Test(admin_url, admin_token, u, testServiceId, testTenantId); return false; } return true; } else { Tear_Down_Delete_Endpoints_Test(admin_url, admin_token, u, testServiceId, testTenantId); return false; } } catch (Exception x) { try { Tear_Down_Delete_Endpoints_Test(admin_url, admin_token, u, testServiceId, testTenantId); } catch { Delete_Test_Service(testServiceId, admin_url2, admin_token); Delete_Test_Tenant(testTenantId, admin_url2, admin_token); } throw x; } } catch (Exception x) { Delete_Test_Tenant(testTenantId, admin_url2, admin_token); throw x; } } catch (Exception x) { throw x; } return true; }
//==============================================================================// // // Get User by Name // // //==============================================================================// public static string GetUserByName(string url, string AdminID, string UserName) { User return_user = new User(); string ret = string.Empty; try { string user_url = url + "/v2.0/user?name=" + UserName; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(user_url); webRequest.Method = "GET"; webRequest.ServicePoint.Expect100Continue = false; webRequest.Headers.Add("X-Auth-Token", AdminID); webRequest.Timeout = 2000; HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); Stream resStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(resStream); ret = reader.ReadToEnd(); //return_user = StackUser.Parse(ret); return ret; } catch (Exception x) { throw OpenStackObject.Parse_Error(x); } }
public Boolean setUp(string admin_url, string admin_token, string testTenantName, int iterations) { try { //create test tenant Create_Test_Tenant(testTenantName, admin_url + "/v2.0/", admin_token); try { //create test user string testUserName = "******"; string testUserPass = "******"; roleTestUser = User.Add(admin_url, testUserName, testUserPass, "true", role_testTenantid, "null", admin_token); roleTestToken = Token.Request_NoTenant(admin_url, roleTestUser.name, roleTestUser.password); if (roleTestToken.token_error.Equals(String.Empty)) { //initialize list of test user roles disposableRoles = User.List_Roles(admin_url, roleTestUser.id, role_testTenantid, admin_token); BaseCount = disposableRoles.Count; try { for (int i = 0; i < iterations; i++) { Role r = Role.Add(admin_url, "UserAddRoleTest" + i, admin_token); User.AddRoleToUser(admin_url, roleTestUser.id, roleTestUser.tenantid, r.id, admin_token); disposableRoles.Add(r); } } catch (Exception x) { tearDown(admin_url, admin_token); return false; } } else { tearDown(admin_url, admin_token); } } catch (Exception x) { try { tearDown(admin_url, admin_token); } catch { Delete_Test_Tenant(admin_url + "/v2.0/", admin_token); } throw x; } } catch (Exception x) { throw x; } return true; }
protected void Page_Load(object sender, EventArgs e) { if (sender != null && sender.GetType().Equals(this.GetType())) { if (((UsersGet)sender).CurrentTest != null) { userGetTest = ((UsersGet)sender).CurrentTest; user = ((UsersGet)sender).userTest; } else { userGetTest = new TestGetUser(); user = new User(); } } else { userGetTest = new TestGetUser(); user = new User(); } }
//==============================================================================// // // Get User by ID // // //==============================================================================// public static User GetUserById(string url, string AdminID, string UserId) { User return_user = new User(); string ret = string.Empty; try { string user_url = url + "/v2.0/users/" + UserId; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(user_url); webRequest.Method = "GET"; webRequest.ServicePoint.Expect100Continue = false; webRequest.Headers.Add("X-Auth-Token", AdminID); webRequest.Timeout = 2000; HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); Stream resStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(resStream); ret = reader.ReadToEnd(); try { return_user = User.Parse(ret); } catch { throw new BadJson("Syntax of argument was incorrect"); } return return_user; } catch (Exception x) { throw OpenStackObject.Parse_Error(x); } }
public Boolean Tear_Down_EmptyList_Endpoints_Test(string admin_url, string admin_token, User u, string testServiceId, string testTenantId) { Boolean ret = true; try { User.Delete(admin_url, u.id, admin_token); } catch { } ret |= Delete_Test_Service(testServiceId, admin_url + "/v2.0/", admin_token); ret |= Delete_Test_Tenant(testTenantId, admin_url + "/v2.0/", admin_token); if (ret == true) { endpoint_testServiceid = String.Empty; endpoint_testTenantid = String.Empty; } return ret; }
//==============================================================================// // // List Users // // //==============================================================================// public static List<User> List(string url, string User_Token) { string server_return_string = string.Empty; string list_url = url + "/v2.0/users/"; try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(list_url); webRequest.Method = "GET"; webRequest.ServicePoint.Expect100Continue = false; webRequest.Headers.Add("X-Auth-Token", User_Token); webRequest.Timeout = 2000; HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); Stream resStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(resStream); server_return_string = reader.ReadToEnd(); try { JArray parsed_user_list = Parse_List_Of_Users(server_return_string); List<User> User_List = new List<User>(); int counter; for (counter = 0; counter < parsed_user_list.Count(); counter++) { User newUser = new User(); newUser.name = parsed_user_list[counter]["name"].ToString(); newUser.enabled = parsed_user_list[counter]["enabled"].ToString(); newUser.email = parsed_user_list[counter]["email"].ToString(); newUser.id = parsed_user_list[counter]["id"].ToString(); newUser.tenantid = parsed_user_list[counter]["tenantId"].ToString(); User_List.Add(newUser); } return User_List; } catch { throw new BadJson("Syntax of argument was incorrect"); } } catch (Exception x) { throw OpenStackObject.Parse_Error(x); } }
public Boolean run(string admin_url, string admin_token, string userID) { try { user = User.GetUserById(admin_url, admin_token, userID); return true; } catch (Exception x) { tearDown(admin_url, admin_token); throw x; } }
//==============================================================================// // // Update User Password // // //==============================================================================// public static User Update_Password(string url, string admin_token, string user_id, string user_name, string password) { string update_url = url + "/v2.0/users/" + user_id; string ret = string.Empty; User updated_user = new User(); string postData = "{ " + "\"user\": { " + "\"name\":\"" + user_name + "\"," + "\"password\":\"" + password + "\"" + "}" + "}"; StreamWriter requestWriter; try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(update_url); webRequest.Method = "PUT"; webRequest.Headers.Add("X-Auth-Token", admin_token); webRequest.ServicePoint.Expect100Continue = false; webRequest.Timeout = 1000; webRequest.ContentType = "application/json"; requestWriter = new StreamWriter(webRequest.GetRequestStream()); requestWriter.Write(postData); requestWriter.Close(); HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); Stream resStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(resStream); ret = reader.ReadToEnd(); //parse the return to extract the variables. try { JObject oServerReturn = JObject.Parse(ret); String userStr = oServerReturn["user"].ToString(); JObject oUser = JObject.Parse(userStr); string userid = oUser["id"].ToString(); string username = oUser["name"].ToString(); string extra_string = oUser["extra"].ToString(); JObject oExtra = JObject.Parse(extra_string); string user_password = oExtra["password"].ToString(); string user_enabled = oExtra["enabled"].ToString(); string user__email = oExtra["email"].ToString(); string user_tenantId = oExtra["tenantId"].ToString(); // load the variables into a user object updated_user.id = userid; updated_user.name = username; updated_user.enabled = user_enabled; updated_user.email = user__email; updated_user.tenantid = user_tenantId; updated_user.error = ""; } catch { throw new BadJson("Syntax of argument was incorrect"); } // return a User object return (updated_user); } catch (Exception x) { throw OpenStackObject.Parse_Error(x); } }
public Boolean setUp(string admin_url, string admin_token, string testTenantName) { try { Create_Test_Tenant(testTenantName, admin_url, admin_token, ref testTenantId); try { string testUserName = "******"; string testUserPass = "******"; getTestUser = User.Add(admin_url, testUserName, testUserPass, "true", testTenantId, "null", admin_token); } catch (Exception x) { try { tearDown(admin_url, admin_token); } catch { Delete_Test_Tenant(admin_url, admin_token, testTenantId); } throw x; } } catch (Exception x) { throw x; } return true; }
protected void btnTest1_Click(object sender, EventArgs e) { lstbxUsers.Items.Clear(); lstbxAfter.Items.Clear(); try { lblCreateUserPassFail.Visible = userUpdateTest.setUp(txtbAdminURL.Text, LoginSession.userToken.token_id, "tstUserTen_1", "tstUserTen_2"); lblCreateUserPassFail.Text = "PASS"; lstbxUsers.Items.Clear(); Boolean ret = true; String output = String.Empty; before = userUpdateTest.getTestUser(); //End Set Up ret |= userUpdateTest.run(txtbAdminURL.Text, LoginSession.userToken.token_id, userUpdateTest.updateTestUser.id, "updatedUsername1", "null", "true", userUpdateTest.testTenantId); updatesList.Add(userUpdateTest.getTestUser()); ret |= userUpdateTest.run(txtbAdminURL.Text, LoginSession.userToken.token_id, userUpdateTest.updateTestUser.id, "updatedUsername1", "updatedEmail1", "true", userUpdateTest.testTenantId); updatesList.Add(userUpdateTest.getTestUser()); /* lblProgress.Text = "Before run 3"; ret |= userUpdateTest.run(txtbAdminURL.Text, LoginSession.userToken.token_id, "updatedUsername1", "updatedEmail1", "false", userUpdateTest.testTenantId); updatesList.Add(userUpdateTest.getTestUser()); */ ret |= userUpdateTest.run(txtbAdminURL.Text, LoginSession.userToken.token_id, userUpdateTest.updateTestUser.id, "updatedUsername1", "updatedEmail1", "true", userUpdateTest.testTenantId2); updatesList.Add(userUpdateTest.getTestUser()); ret |= userUpdateTest.run(txtbAdminURL.Text, LoginSession.userToken.token_id, userUpdateTest.updateTestUser.id, "updatedUsername2", "updatedEmail2", "true", userUpdateTest.testTenantId); updatesList.Add(userUpdateTest.getTestUser()); lblRunTest1.Visible = ret; lblRunTest1.Text = "PASS"; lstbxUsers.Items.Add(before.name + " " + before.id); lstbxAfter.Items.Clear(); try { lblTearDown1.Visible = userUpdateTest.tearDown(txtbAdminURL.Text, LoginSession.userToken.token_id); lblTearDown1.Text = "PASS"; for (int i = 0; i < updatesList.Count(); ++i) { lstbxAfter.Items.Add(updatesList[i].name + " " + updatesList[i].id); } } catch (Exception x) { lblUser.Text = x.Message; lblCreateUserPassFail.Visible = true; lblCreateUserPassFail.Text = "FAIL"; } } //End Run Test catch (Exception x) { lblUser.Text = x.Message; lblCreateUserPassFail.Visible = true; lblCreateUserPassFail.Text = "FAIL"; pnlUserInfo.Visible = true; } }
public bool compareUpdateAndNew(User u) { if (u.name != updateTestUser.name) return false; if (u.email != updateTestUser.email) return false; if (u.enabled != updateTestUser.enabled) return false; if (u.tenantid != updateTestUser.tenantid) return false; return true; }