From 5c574201cbfa97329863a3d65be590d23881cd8e Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Tue, 26 Nov 2019 15:03:27 +0500 Subject: [PATCH] test_issueSSL --- manageSSL/tests.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++ manageSSL/views.py | 34 +++++++++++---------- 2 files changed, 94 insertions(+), 15 deletions(-) diff --git a/manageSSL/tests.py b/manageSSL/tests.py index 5982e6bcd..7bb9e0ebb 100755 --- a/manageSSL/tests.py +++ b/manageSSL/tests.py @@ -2,5 +2,80 @@ from __future__ import unicode_literals from django.test import TestCase +import json +import requests +import urllib3 +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging +from plogical.processUtilities import ProcessUtilities + +urllib3.disable_warnings() + # Create your tests here. + + +class TestManageSSL(TestCase): + httpClient = requests.Session() + + def MakeRequest(self, endPoint, data): + json_data = json.dumps(data) + path = 'https://cyberpanel.xyz:8090/%s' % (endPoint) + result = TestManageSSL.httpClient.post(path, data=json_data, verify=False) + return json.loads(result.text) + + def MakeRequestRaw(self, path): + result = requests.get(path) + return str(result.text) + + def setupConnection(self): + try: + import MySQLdb as mysql + import MySQLdb.cursors as cursors + conn = mysql.connect(user='admin_hello', passwd='helloworld', cursorclass=cursors.SSCursor) + cursor = conn.cursor() + return conn, cursor + except: + return 0, 0 + + def setUp(self): + ## Verify login + + data_ret = {'username': 'admin', 'password': '1234567'} + response = self.MakeRequest('verifyLogin', data_ret) + self.assertEqual(response['loginStatus'], 1) + + def test_issueSSL(self): + ## Issue SSL + + data_ret = {'virtualHost': 'cyberpanel.xyz'} + + response = self.MakeRequest('manageSSL/issueSSL', data_ret) + + self.assertEqual(response['status'], 1) + + ## Verify SSL + + command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz') + ProcessUtilities.normalExecutioner(command) + + command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz') + ProcessUtilities.normalExecutioner(command) + + command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz') + ProcessUtilities.normalExecutioner(command) + + path = '/home/%s/public_html/index.html' % ('cyberpanel.xyz') + + writeToFile = open(path, 'w') + writeToFile.write('CyberPanel') + writeToFile.close() + + exists = 0 + if self.MakeRequestRaw('https://cyberpanel.xyz').find('CyberPanel') > -1: + exists = 1 + + self.assertEqual(exists, 1) + + + + diff --git a/manageSSL/views.py b/manageSSL/views.py index e6051d40e..99aa571d7 100755 --- a/manageSSL/views.py +++ b/manageSSL/views.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.shortcuts import render,redirect +from django.shortcuts import render, redirect from loginSystem.views import loadLoginPage -from websiteFunctions.models import Websites,ChildDomains +from websiteFunctions.models import Websites, ChildDomains from loginSystem.models import Administrator from plogical.virtualHostUtilities import virtualHostUtilities from django.http import HttpResponse @@ -13,6 +13,8 @@ import subprocess from plogical.acl import ACLManager from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging from plogical.processUtilities import ProcessUtilities + + # Create your views here. @@ -24,6 +26,7 @@ def loadSSLHome(request): except KeyError: return redirect(loadLoginPage) + def manageSSL(request): try: userID = request.session['userID'] @@ -38,10 +41,11 @@ def manageSSL(request): websitesName = ACLManager.findAllSites(currentACL, userID) - return render(request, 'manageSSL/manageSSL.html',{'websiteList':websitesName}) + return render(request, 'manageSSL/manageSSL.html', {'websiteList': websitesName}) except KeyError: return redirect(loadLoginPage) + def issueSSL(request): try: userID = request.session['userID'] @@ -65,10 +69,6 @@ def issueSSL(request): else: return ACLManager.loadErrorJson() - - adminEmail = "" - path = "" - try: website = ChildDomains.objects.get(domain=virtualHost) adminEmail = website.master.adminEmail @@ -87,7 +87,7 @@ def issueSSL(request): if output.find("1,None") > -1: pass else: - data_ret = {'status': 0 ,"SSL": 0, + data_ret = {'status': 0, "SSL": 0, 'error_message': output} json_data = json.dumps(data_ret) return HttpResponse(json_data) @@ -102,7 +102,7 @@ def issueSSL(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) - except BaseException,msg: + except BaseException, msg: data_ret = {'status': 0, "SSL": 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) @@ -113,6 +113,7 @@ def issueSSL(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + def sslForHostName(request): try: userID = request.session['userID'] @@ -127,10 +128,11 @@ def sslForHostName(request): websitesName = ACLManager.findAllSites(currentACL, userID) - return render(request, 'manageSSL/sslForHostName.html',{'websiteList':websitesName}) + return render(request, 'manageSSL/sslForHostName.html', {'websiteList': websitesName}) except KeyError: return redirect(loadLoginPage) + def obtainHostNameSSL(request): try: userID = request.session['userID'] @@ -178,7 +180,7 @@ def obtainHostNameSSL(request): ## ssl issue ends - except BaseException,msg: + except BaseException, msg: data_ret = {"status": 0, "SSL": 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) @@ -189,6 +191,7 @@ def obtainHostNameSSL(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + def sslForMailServer(request): try: userID = request.session['userID'] @@ -204,10 +207,11 @@ def sslForMailServer(request): websitesName = ACLManager.findAllSites(currentACL, userID) websitesName = websitesName + ACLManager.findChildDomains(websitesName) - return render(request, 'manageSSL/sslForMailServer.html',{'websiteList':websitesName}) + return render(request, 'manageSSL/sslForMailServer.html', {'websiteList': websitesName}) except KeyError: return redirect(loadLoginPage) + def obtainMailServerSSL(request): try: userID = request.session['userID'] @@ -254,13 +258,13 @@ def obtainMailServerSSL(request): ## ssl issue ends - except BaseException,msg: + except BaseException, msg: data_ret = {"status": 0, "SSL": 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) return HttpResponse(json_data) - except KeyError,msg: + except KeyError, msg: data_ret = {"status": 0, "SSL": 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) - return HttpResponse(json_data) \ No newline at end of file + return HttpResponse(json_data)