mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 21:35:55 +01:00
Add Unit Tests: LS and UM
This commit is contained in:
@@ -1,6 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, Client
|
||||
from django.urls import reverse
|
||||
import json
|
||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||
from loginSystem.models import Administrator
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
|
||||
class TestLogin(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
## Initiate Client
|
||||
|
||||
self.client = Client()
|
||||
self.adminLogin = reverse('adminLogin')
|
||||
self.verifyLogin = reverse('verifyLogin')
|
||||
|
||||
## Create Login User
|
||||
|
||||
response = self.client.get(self.adminLogin)
|
||||
self.assertTemplateUsed(response, 'loginSystem/login.html')
|
||||
|
||||
def test_verify_login(self):
|
||||
|
||||
## Login
|
||||
|
||||
data_ret = {'username': 'admin', 'password': '1234567'}
|
||||
json_data = json.dumps(data_ret)
|
||||
|
||||
response = self.client.post(self.verifyLogin, json_data, content_type="application/json")
|
||||
logging.writeToFile(response.content)
|
||||
json_data = json.loads(response.content)
|
||||
self.assertEqual(json_data['loginStatus'], 1)
|
||||
|
||||
|
||||
## Verify
|
||||
|
||||
response = self.client.get(self.adminLogin)
|
||||
self.assertTemplateUsed(response, 'baseTemplate/homePage.html')
|
||||
##logging.writeToFile(result.content)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
@@ -672,18 +672,27 @@ class virtualHostUtilities:
|
||||
|
||||
## Postfix
|
||||
|
||||
shutil.copy(srcPrivKey, "/etc/postfix/key.pem")
|
||||
shutil.copy(srcFullChain, "/etc/postfix/cert.pem")
|
||||
command = 'ln -s %s /etc/postfix/key.pem' % (srcPrivKey)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'ln -s %s /etc/postfix/cert.pem' % (srcFullChain)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
## Dovecot
|
||||
|
||||
shutil.copy(srcPrivKey, "/etc/pki/dovecot/private/dovecot.pem")
|
||||
shutil.copy(srcFullChain, "/etc/pki/dovecot/certs/dovecot.pem")
|
||||
command = 'ln -s %s /etc/pki/dovecot/private/dovecot.pem' % (srcPrivKey)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'ln -s %s /etc/pki/dovecot/certs/dovecot.pem' % (srcFullChain)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
## Dovecot 2ND
|
||||
|
||||
shutil.copy(srcPrivKey, "/etc/dovecot/key.pem")
|
||||
shutil.copy(srcFullChain, "/etc/dovecot/cert.pem")
|
||||
command = 'ln -s %s /etc/dovecot/key.pem' % (srcPrivKey)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'ln -s %s /etc/dovecot/cert.pem' % (srcFullChain)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
## Update postmaster address dovecot
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
1573973433754 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileLc2y7g"
|
||||
1573973434225 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
|
||||
1573973434225 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
|
||||
1573973434225 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
|
||||
1573973434225 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
|
||||
1573973436114 Marionette INFO Listening on port 37645
|
||||
1573973436175 Marionette WARN TLS certificate errors will be ignored for this session
|
||||
1573973446035 Marionette INFO Stopped listening on port 37645
|
||||
|
||||
###!!! [Parent][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
|
||||
|
||||
1573973852572 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile1rjJBH"
|
||||
1573973853028 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
|
||||
1573973853028 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
|
||||
1573973853028 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
|
||||
1573973853029 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
|
||||
1573973854811 Marionette INFO Listening on port 41103
|
||||
1573973854879 Marionette WARN TLS certificate errors will be ignored for this session
|
||||
[Parent 10908, Gecko_IOThread] WARNING: pipe error (79): Connection reset by peer: file /build/firefox-clezVp/firefox-70.0.1+build1/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 358
|
||||
[Parent 10908, Gecko_IOThread] WARNING: pipe error (76): Connection reset by peer: file /build/firefox-clezVp/firefox-70.0.1+build1/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 358
|
||||
1573973986906 Marionette INFO Stopped listening on port 41103
|
||||
@@ -1,56 +0,0 @@
|
||||
# Generated by Selenium IDE
|
||||
import pytest
|
||||
import time
|
||||
import json
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
from selenium.webdriver.support import expected_conditions
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
|
||||
class TestCreateUser():
|
||||
def setup_method(self, method):
|
||||
self.driver = webdriver.Firefox(executable_path='/usr/bin/firefoxdriver')
|
||||
self.vars = {}
|
||||
|
||||
def teardown_method(self, method):
|
||||
self.driver.quit()
|
||||
|
||||
def test_createUser(self):
|
||||
self.driver.get("https://cyberpanel.xyz:8090/")
|
||||
self.driver.set_window_size(1366, 654)
|
||||
self.driver.find_element(By.NAME, "username").click()
|
||||
self.driver.find_element(By.NAME, "username").send_keys("admin")
|
||||
self.driver.find_element(By.ID, "password").send_keys("hello123")
|
||||
self.driver.find_element(By.ID, "password").send_keys(Keys.ENTER)
|
||||
self.driver.find_element(By.LINK_TEXT, "Users").click()
|
||||
self.driver.find_element(By.CSS_SELECTOR, ".createNewUser span").click()
|
||||
self.driver.find_element(By.CSS_SELECTOR, ".form-group:nth-child(1)").click()
|
||||
self.driver.find_element(By.NAME, "firstName").click()
|
||||
self.driver.find_element(By.NAME, "firstName").send_keys("Usman")
|
||||
self.driver.find_element(By.NAME, "lastName").send_keys("Nasir")
|
||||
self.driver.find_element(By.NAME, "email").send_keys("usman")
|
||||
self.driver.find_element(By.NAME, "email").send_keys(Keys.DOWN)
|
||||
self.driver.find_element(By.NAME, "email").send_keys("usman@cyberpersons.com")
|
||||
self.driver.find_element(By.CSS_SELECTOR, ".form-group:nth-child(4) .form-control").click()
|
||||
dropdown = self.driver.find_element(By.CSS_SELECTOR, ".form-group:nth-child(4) .form-control")
|
||||
dropdown.find_element(By.XPATH, "//option[. = 'user']").click()
|
||||
self.driver.find_element(By.CSS_SELECTOR, ".ng-not-empty > option:nth-child(3)").click()
|
||||
self.driver.find_element(By.NAME, "websitesLimits").click()
|
||||
self.driver.find_element(By.NAME, "websitesLimits").send_keys("50")
|
||||
self.driver.find_element(By.CSS_SELECTOR, ".form-group:nth-child(6) .form-control").send_keys("usman")
|
||||
self.driver.find_element(By.NAME, "password").send_keys("nasir")
|
||||
self.driver.find_element(By.CSS_SELECTOR, ".ng-empty").click()
|
||||
dropdown = self.driver.find_element(By.CSS_SELECTOR, ".form-group:nth-child(9) .form-control")
|
||||
dropdown.find_element(By.XPATH, "//option[. = 'HIGH']").click()
|
||||
self.driver.find_element(By.CSS_SELECTOR, ".ng-untouched > option:nth-child(1)").click()
|
||||
self.driver.find_element(By.CSS_SELECTOR, ".btn-lg").click()
|
||||
self.driver.find_element(By.CSS_SELECTOR, ".alert-success").click()
|
||||
assert self.driver.find_element(By.CSS_SELECTOR, ".alert-success > p").text == "Account with username: usman is successfully created."
|
||||
|
||||
|
||||
ct = TestCreateUser()
|
||||
ct.setup_method('test')
|
||||
ct.test_createUser()
|
||||
ct.teardown_method('test')
|
||||
@@ -1,6 +1,58 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, Client
|
||||
from django.urls import reverse
|
||||
import json
|
||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||
from loginSystem.models import Administrator
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
|
||||
class TestLogin(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
## Initiate Client
|
||||
|
||||
self.client = Client()
|
||||
self.adminLogin = reverse('adminLogin')
|
||||
self.verifyLogin = reverse('verifyLogin')
|
||||
|
||||
## Create Login User
|
||||
|
||||
response = self.client.get(self.adminLogin)
|
||||
self.assertTemplateUsed(response, 'loginSystem/login.html')
|
||||
|
||||
self.submitUserCreation = reverse('submitUserCreation')
|
||||
|
||||
## Verify login
|
||||
|
||||
data_ret = {'username': 'admin', 'password': '1234567'}
|
||||
json_data = json.dumps(data_ret)
|
||||
|
||||
response = self.client.post(self.verifyLogin, json_data, content_type="application/json")
|
||||
logging.writeToFile(response.content)
|
||||
json_data = json.loads(response.content)
|
||||
self.assertEqual(json_data['loginStatus'], 1)
|
||||
|
||||
def test_submitUserCreation(self):
|
||||
|
||||
## Login
|
||||
|
||||
data_ret = {'firstName': 'Usman', 'lastName': 'Nasir', 'email': 'usman@cyberpersons.com', 'userName': 'usman',
|
||||
'password': '1234567', 'websitesLimit': 50, 'selectedACL':'user', 'securityLevel': 'HIGH'}
|
||||
json_data = json.dumps(data_ret)
|
||||
|
||||
response = self.client.post(self.submitUserCreation, json_data, content_type="application/json")
|
||||
logging.writeToFile(response.content)
|
||||
json_data = json.loads(response.content)
|
||||
|
||||
|
||||
self.assertEqual(json_data['status'], 1)
|
||||
self.assertEqual(json_data['createStatus'], 1)
|
||||
|
||||
self.assertEqual(Administrator.objects.filter(userName='usman').count(), 1)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user