2017-10-24 19:16:36 +05:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
2019-11-24 12:14:18 +05:00
from django . test import TestCase
2019-11-19 18:43:52 +05:00
import json
from plogical . CyberCPLogFileWriter import CyberCPLogFileWriter as logging
import requests
import time
2019-11-24 12:14:18 +05:00
from plogical . processUtilities import ProcessUtilities
import urllib3
urllib3 . disable_warnings ( )
2017-10-24 19:16:36 +05:00
# Create your tests here.
2019-11-19 18:43:52 +05:00
class TestWebsiteManagement ( TestCase ) :
httpClient = requests . Session ( )
def MakeRequest ( self , endPoint , data ) :
json_data = json . dumps ( data )
path = ' https://cyberpanel.xyz:8090/ %s ' % ( endPoint )
result = TestWebsiteManagement . 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 setUp ( self ) :
## Verify login
2019-11-24 12:14:18 +05:00
data_ret = { ' username ' : ' admin ' , ' password ' : ' 1234567 ' }
2019-11-19 18:43:52 +05:00
response = self . MakeRequest ( ' verifyLogin ' , data_ret )
self . assertEqual ( response [ ' loginStatus ' ] , 1 )
def test_submitWebsiteCreation ( self ) :
## Login
data_ret = { ' domainName ' : ' hello.cyberpanel.xyz ' , ' adminEmail ' : ' usman@cyberpersons.com ' , ' phpSelection ' : ' PHP 7.1 ' ,
' package ' : ' Default ' , ' websiteOwner ' : ' admin ' , ' ssl ' : 0 , ' dkimCheck ' : 0 , ' openBasedir ' : 0 }
response = self . MakeRequest ( ' websites/submitWebsiteCreation ' , data_ret )
time . sleep ( 10 )
self . assertEqual ( response [ ' status ' ] , 1 )
exists = 0
if self . MakeRequestRaw ( ' http://hello.cyberpanel.xyz ' ) . find ( ' CyberPanel ' ) > - 1 :
exists = 1
self . assertEqual ( exists , 1 )
2019-11-24 12:14:18 +05:00
def test_submitWebsiteDeletion ( self ) :
2019-11-19 18:43:52 +05:00
2019-11-24 12:14:18 +05:00
## Login
data_ret = { ' websiteName ' : ' hello.cyberpanel.xyz ' }
response = self . MakeRequest ( ' websites/submitWebsiteDeletion ' , data_ret )
time . sleep ( 10 )
self . assertEqual ( response [ ' status ' ] , 1 )
def test_submitWebsiteModify ( self ) :
data_ret = { ' domainName ' : ' hey.cyberpanel.xyz ' , ' adminEmail ' : ' usman@cyberpersons.com ' ,
2019-11-20 15:55:38 +05:00
' phpSelection ' : ' PHP 7.1 ' ,
' package ' : ' Default ' , ' websiteOwner ' : ' admin ' , ' ssl ' : 0 , ' dkimCheck ' : 0 , ' openBasedir ' : 0 }
self . MakeRequest ( ' websites/submitWebsiteCreation ' , data_ret )
2019-11-24 12:14:18 +05:00
time . sleep ( 10 )
2019-11-20 00:11:22 +05:00
2019-11-24 12:14:18 +05:00
##
2019-11-20 00:11:22 +05:00
2019-11-20 15:18:36 +05:00
data_ret = { ' domain ' : ' hey.cyberpanel.xyz ' , ' email ' : ' usman@cyberpersons.com ' , ' phpVersion ' : ' PHP 7.3 ' ,
' packForWeb ' : ' Default ' , ' admin ' : ' admin ' }
response = self . MakeRequest ( ' websites/saveWebsiteChanges ' , data_ret )
2019-11-20 00:11:22 +05:00
time . sleep ( 5 )
self . assertEqual ( response [ ' status ' ] , 1 )
2019-11-20 15:18:36 +05:00
phpInfoPath = ' /home/hey.cyberpanel.xyz/public_html/info.php '
content = """ <?php
2019-11-20 00:11:22 +05:00
2019-11-20 15:18:36 +05:00
phpinfo ( ) ;
2019-11-20 12:49:15 +05:00
2019-11-20 15:18:36 +05:00
? >
"""
writeToFile = open ( phpInfoPath , ' w ' )
writeToFile . write ( content )
writeToFile . close ( )
2019-11-20 12:49:15 +05:00
exists = 0
2019-11-20 15:18:36 +05:00
if self . MakeRequestRaw ( ' http://hey.cyberpanel.xyz/info.php ' ) . find ( ' PHP 7.3 ' ) > - 1 :
2019-11-20 12:49:15 +05:00
exists = 1
self . assertEqual ( exists , 1 )
2019-11-20 15:55:38 +05:00
def test_submitWebsiteStatus ( self ) :
2019-11-24 12:14:18 +05:00
data_ret = { ' domainName ' : ' suspend.cyberpanel.xyz ' , ' adminEmail ' : ' usman@cyberpersons.com ' ,
' phpSelection ' : ' PHP 7.1 ' ,
' package ' : ' Default ' , ' websiteOwner ' : ' admin ' , ' ssl ' : 0 , ' dkimCheck ' : 0 , ' openBasedir ' : 0 }
self . MakeRequest ( ' websites/submitWebsiteCreation ' , data_ret )
2019-11-20 15:55:38 +05:00
## Suspend check
data_ret = { ' websiteName ' : ' suspend.cyberpanel.xyz ' , ' state ' : ' Suspend ' }
response = self . MakeRequest ( ' websites/submitWebsiteStatus ' , data_ret )
time . sleep ( 5 )
self . assertEqual ( response [ ' websiteStatus ' ] , 1 )
exists = 0
if self . MakeRequestRaw ( ' http://suspend.cyberpanel.xyz ' ) . find ( ' 404 ' ) > - 1 or self . MakeRequestRaw ( ' http://suspend.cyberpanel.xyz ' ) . find ( ' Access to this resource on the server is denied! ' ) > - 1 :
exists = 1
self . assertEqual ( exists , 1 )
suspend = 0
import os
if os . path . exists ( ' /usr/local/lsws/conf/vhosts/suspend.cyberpanel.xyz-suspended ' ) :
suspend = 1
self . assertEqual ( suspend , 1 )
## Unsuspend check
data_ret = { ' websiteName ' : ' suspend.cyberpanel.xyz ' , ' state ' : ' Unsuspend ' }
response = self . MakeRequest ( ' websites/submitWebsiteStatus ' , data_ret )
time . sleep ( 5 )
self . assertEqual ( response [ ' websiteStatus ' ] , 1 )
exists = 0
if self . MakeRequestRaw ( ' http://suspend.cyberpanel.xyz ' ) . find ( ' CyberPanel ' ) > - 1 :
exists = 1
self . assertEqual ( exists , 1 )
suspend = 0
import os
if os . path . exists ( ' /usr/local/lsws/conf/vhosts/suspend.cyberpanel.xyz ' ) :
suspend = 1
self . assertEqual ( suspend , 1 )
2019-11-21 14:58:46 +05:00
def test_installWordpress ( self ) :
2019-11-24 12:14:18 +05:00
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 )
2019-11-21 14:58:46 +05:00
## Suspend check
data_ret = { ' domain ' : ' cyberpanel.xyz ' , ' home ' : ' 1 ' , ' blogTitle ' : ' Unit Test ' , ' adminUser ' : ' cyberpanel ' ,
' passwordByPass ' : ' helloworld ' , ' adminEmail ' : ' usman@cyberpersons.com ' }
response = self . MakeRequest ( ' websites/installWordpress ' , data_ret )
time . sleep ( 2 )
self . assertEqual ( response [ ' status ' ] , 1 )
tempStatusPath = response [ ' tempStatusPath ' ]
## Wait for install to complete
2019-11-24 12:14:18 +05:00
data_ret = { ' statusFile ' : tempStatusPath , ' domainName ' : ' cyberpanel.xyz ' }
2019-11-21 14:58:46 +05:00
while True :
response = self . MakeRequest ( ' websites/installWordpressStatus ' , data_ret )
if response [ ' abort ' ] == 1 :
if response [ ' installStatus ' ] :
break
else :
logging . writeToFile ( response [ ' error_message ' ] )
break
exists = 0
if self . MakeRequestRaw ( ' http://cyberpanel.xyz ' ) . find ( ' Unit Test ' ) > - 1 :
exists = 1
self . assertEqual ( exists , 1 )
2019-11-20 15:55:38 +05:00
2019-11-24 12:14:18 +05:00
def test_installJoomla ( self ) :
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 )
## Suspend check
data_ret = { ' domain ' : ' cyberpanel.xyz ' , ' home ' : ' 1 ' , ' sitename ' : ' Unit Test Joomla ' , ' username ' : ' cyberpanel ' ,
' passwordByPass ' : ' helloworld ' , ' prefix ' : ' db_ ' }
response = self . MakeRequest ( ' websites/installJoomla ' , data_ret )
time . sleep ( 2 )
self . assertEqual ( response [ ' status ' ] , 1 )
tempStatusPath = response [ ' tempStatusPath ' ]
## Wait for install to complete
data_ret = { ' statusFile ' : tempStatusPath , ' domainName ' : ' cyberpanel.xyz ' }
while True :
response = self . MakeRequest ( ' websites/installWordpressStatus ' , data_ret )
time . sleep ( 1 )
if response [ ' abort ' ] == 1 :
if response [ ' installStatus ' ] == 1 :
break
else :
logging . writeToFile ( response [ ' error_message ' ] )
break
exists = 0
if self . MakeRequestRaw ( ' http://cyberpanel.xyz ' ) . find ( ' Unit Test Joomla ' ) > - 1 :
exists = 1
self . assertEqual ( exists , 1 )
2019-11-24 12:29:36 +05:00
def test_prestaShopInstall ( self ) :
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 )
## Suspend check
data_ret = { ' domain ' : ' cyberpanel.xyz ' , ' home ' : ' 1 ' , ' shopName ' : ' Unit Test PrestaShop ' , ' firstName ' : ' Usman ' , ' lastName ' : ' Nasir ' ,
' passwordByPass ' : ' helloworld ' , ' databasePrefix ' : ' db_ ' , ' email ' : ' usman@cyberpersons.com ' }
response = self . MakeRequest ( ' websites/prestaShopInstall ' , data_ret )
logging . writeToFile ( ' ps: ' + str ( response ) )
time . sleep ( 2 )
self . assertEqual ( response [ ' status ' ] , 1 )
tempStatusPath = response [ ' tempStatusPath ' ]
## Wait for install to complete
data_ret = { ' statusFile ' : tempStatusPath , ' domainName ' : ' cyberpanel.xyz ' }
while True :
response = self . MakeRequest ( ' websites/installWordpressStatus ' , data_ret )
time . sleep ( 1 )
if response [ ' abort ' ] == 1 :
if response [ ' installStatus ' ] == 1 :
break
else :
logging . writeToFile ( response [ ' error_message ' ] )
break
exists = 0
if self . MakeRequestRaw ( ' http://cyberpanel.xyz ' ) . find ( ' Unit Test PrestaShop ' ) > - 1 :
exists = 1
self . assertEqual ( exists , 1 )
2019-11-20 15:55:38 +05:00
2019-11-20 15:18:36 +05:00
2019-11-19 18:43:52 +05:00