update tests and pro data on template

* remove using complex execute script on selenium for select, only check if  click doesn't return an error
*start adding conditions with pro data to display useful details or alerts
This commit is contained in:
Jordan Blasenhauer 2024-02-28 17:52:12 +01:00
parent 1e3de2fbf2
commit 5213c63d8d
11 changed files with 88 additions and 55 deletions

File diff suppressed because one or more lines are too long

View file

@ -88,6 +88,12 @@
<!-- end dropdown-->
</div>
<!-- end mobile tabs -->
{% set global_info = {
"message" : "You are using pro version" if is_pro_version and pro_status else "Pro version is expired" if is_pro_version and not pro_status else "You are using free version",
"link_message" : "Upgrade to pro" if not is_pro_version else "Renew my license" if is_pro_version and not pro_status else "",
"icon" : "pro" if is_pro_version and pro_status else "free"
}
%}
<div data-plugin-item="global"
class="grid grid-cols-12 w-full justify-items-center">
<div class="col-span-12">
@ -96,18 +102,12 @@
</h5>
<div class="flex justify-center items-center">
<p class="mb-0 mr-2 dark:text-gray-300">
You are using
{% if is_pro_version %}
pro
{% else %}
free
{% endif %}
version
{{global_info['message']}}
</p>
<div role="img"
aria-label="version"
class="dark:brightness-90 inline-block w-8 h-8 text-center rounded-circle bg-yellow-500">
{% if is_pro_version %}
{% if global_info['icon'] == 'pro' %}
<svg class="leading-none text-lg relative scale-[0.6]"
viewBox="0 0 48 46"
fill="none"
@ -127,12 +127,35 @@
{% endif %}
</div>
</div>
{% if not is_pro_version %}
{% if global_info['link_message'] %}
<div class="flex justify-center mt-2">
<a class="text-center font-semibold text-yellow-500 underline"
href="https://panel.bunkerweb.io/">Upgrade to pro</a>
href="https://panel.bunkerweb.io/">{{ global_info['link_message'] }}</a>
</div>
{% endif %}
{% if is_pro_version and pro_status %}
<div class="mt-2 flex flex-col justify-center items-center">
{% if pro_expire %}
<p class="my-2 mr-2 dark:text-gray-300 text-center">
Your license is valid until {{ pro_expire }}
</p>
{% endif %}
{% if pro_services %}
<p class="my-2 mr-2 dark:text-gray-300 text-center">
You can handle {{ pro_services }} services
</p>
{% endif %}
{% if pro_overlapped %}
<p class="my-2 mr-2 text-red-500 font-bold dark:brightness-95 text-center">
You have more services than allowed by your license. Upgrade your license or move some services to draft mode before your license lockout.
</p>
{% endif %}
</div>
{% endif %}
</div>
</div>
<div data-plugin-item="username"

View file

@ -93,7 +93,7 @@
<button data-services-modal-submit type="submit" class="mb-4 valid-btn">Save</button>
</div>
<!-- end action button-->
<p data-services-modal-error-msg class="hidden text-red-500 dark:opacity-80 mb-0 text-center"></p>
<p data-services-modal-error-msg class="hidden text-red-500 font-bold dark:opacity-80 mb-0 text-center"></p>
</form>
<!-- end new and edit form -->
<!-- delete form-->

View file

@ -6,6 +6,11 @@
class="{% if loop.index != 1 %}hidden{% endif %} w-full">
<!-- title and desc -->
<div class="col-span-12" data-setting-header>
{% if (plugin['type'] == "pro" and not is_pro_version) or (plugin['type'] == "pro" and is_pro_version and not pro_status) %}
<p class="ml-2 mt-0 mb-2 mr-2 text-red-500 font-bold dark:brightness-95 text-sm">
You need a valid pro license to use this plugin
</p>
{% endif %}
<div class="flex justify-start items-center">
<h5 class="transition duration-300 ease-in-out ml-2 font-bold text-md uppercase dark:text-white/90 mb-0">
{{ plugin['name'] }} <span>{{ plugin['version'] }}</span>
@ -25,7 +30,7 @@
{% if plugin['type'] == "pro" %}
<a {% if not is_pro_version %}target="_blank" rel="noopener"{% endif %}
aria-label="pro plugin"
class="hover:-translate-y-px mx-1 -translate-y-0.5"
class="hover:-translate-y-px mx-1 -translate-y-0.5 ml-1"
href="{% if not is_pro_version %}https://panel.bunkerweb.io/{% else %}javascript:void(0){% endif %}">
<svg class="h-6 w-6 dark:brightness-90"
viewBox="0 0 48 46"
@ -38,9 +43,10 @@
{% endif %}
</div>
<div class="transition duration-300 ease-in-out dark:opacity-90 ml-2 text-sm mb-2 dark:text-gray-400">
{{ plugin['description'] }}
<div class="transition duration-300 ease-in-out dark:opacity-90 ml-2 ">
<p class="text-sm dark:text-gray-400 mb-1">{{ plugin['description'] }}</p>
</div>
</div>
<!-- end title and desc -->
<div data-plugin-settings class="w-full grid grid-cols-12">

View file

@ -7,7 +7,7 @@ from selenium.webdriver.remote.webelement import WebElement
from selenium.common.exceptions import TimeoutException
from wizard import DRIVER
from utils import access_page, assert_button_click, safe_get_element, verify_select_filters
from utils import access_page, assert_button_click, safe_get_element
exit_code = 0
@ -88,9 +88,10 @@ try:
key_word_filter_input.send_keys("")
# Test select filters
select_filters = [{"name": "reason", "id": "reason", "value": "all", "update_value": "123456"}, {"name": "range", "id": "term", "value": "all", "update_value": "123456"}]
select_filters = [{"name": "reason", "id": "reason", "value": "all"}, {"name": "range", "id": "term", "value": "all"}]
verify_select_filters(DRIVER, "bans", select_filters)
for item in select_filters:
DRIVER.execute_script(f"""document.querySelector('[data-bans-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
log_info("Bans found, trying to delete them ...")

View file

@ -7,7 +7,7 @@ from selenium.webdriver.remote.webelement import WebElement
from selenium.common.exceptions import TimeoutException
from wizard import DRIVER, UI_URL
from utils import access_page, assert_button_click, safe_get_element, verify_select_filters
from utils import access_page, assert_button_click, safe_get_element
exit_code = 0
@ -39,12 +39,13 @@ try:
# Test select filters
select_filters = [
{"name": "Success state", "id": "success", "value": "all", "update_value": "123456"},
{"name": "Reload state", "id": "reload", "value": "all", "update_value": "123456"},
{"name": "Run time", "id": "every", "value": "all", "update_value": "123456"},
{"name": "Success state", "id": "success", "value": "all"},
{"name": "Reload state", "id": "reload", "value": "all"},
{"name": "Run time", "id": "every", "value": "all"},
]
verify_select_filters(DRIVER, "jobs", select_filters)
for item in select_filters:
DRIVER.execute_script(f"""document.querySelector('[data-jobs-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
log_info("Keyword filter is working, trying to filter by success state ...")

View file

@ -15,6 +15,23 @@ try:
log_info("Navigating to the logs page ...")
access_page(DRIVER, "/html/body/aside[1]/div[1]/div[3]/ul/li[11]/a", "logs")
log_info("Trying filters ...")
key_word_filter_input = safe_get_element(DRIVER, "js", 'document.querySelector("input#keyword")')
assert isinstance(key_word_filter_input, WebElement), "Key word filter input is not a WebElement"
key_word_filter_input.send_keys("Antibot")
# Reset
key_word_filter_input.send_keys("")
# Test select filters
select_filters = [
{"name": "Types", "id": "types", "value": "all"},
]
for item in select_filters:
DRIVER.execute_script(f"""document.querySelector('[data-logs-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
log_info("Selecting correct instance ...")
assert_button_click(DRIVER, "//button[@data-logs-setting-select='instances']")

View file

@ -10,7 +10,7 @@ from selenium.common.exceptions import TimeoutException
from wizard import DRIVER, UI_URL
from base import TEST_TYPE
from utils import access_page, assert_button_click, safe_get_element, wait_for_service, verify_select_filters
from utils import access_page, assert_button_click, safe_get_element, wait_for_service
exit_code = 0
@ -53,9 +53,12 @@ try:
# Test select filters
select_filters = [
{"name": "Types", "id": "types", "value": "all", "update_value": "123456"},
{"name": "Types", "id": "types", "value": "all"},
]
for item in select_filters:
DRIVER.execute_script(f"""document.querySelector('[data-plugins-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
verify_select_filters(DRIVER, "plugins", select_filters)
log_info("The filter is working, trying to add a bad plugin ...")

View file

@ -8,7 +8,7 @@ from selenium.webdriver.remote.webelement import WebElement
from selenium.common.exceptions import TimeoutException
from wizard import DRIVER
from utils import access_page, safe_get_element, verify_select_filters
from utils import access_page, safe_get_element
exit_code = 0
@ -41,13 +41,14 @@ try:
# Test select filters
select_filters = [
{"name": "Country", "id": "country", "value": "all", "update_value": "123456"},
{"name": "Method", "id": "method", "value": "all", "update_value": "123456"},
{"name": "Status code", "id": "status", "value": "all", "update_value": "123456"},
{"name": "Reason", "id": "reason", "value": "all", "update_value": "123456"},
{"name": "Country", "id": "country", "value": "all"},
{"name": "Method", "id": "method", "value": "all"},
{"name": "Status code", "id": "status", "value": "all"},
{"name": "Reason", "id": "reason", "value": "all"},
]
verify_select_filters(DRIVER, "reports", select_filters)
for item in select_filters:
DRIVER.execute_script(f"""document.querySelector('[data-reports-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
filter_input = safe_get_element(DRIVER, By.ID, "keyword")
assert isinstance(filter_input, WebElement), "Keyword filter input is not a WebElement"

View file

@ -9,7 +9,7 @@ from selenium.common.exceptions import TimeoutException
from wizard import DRIVER
from base import TEST_TYPE
from utils import access_page, assert_alert_message, assert_button_click, safe_get_element, wait_for_service, verify_select_filters
from utils import access_page, assert_alert_message, assert_button_click, safe_get_element, wait_for_service
exit_code = 0
@ -304,11 +304,12 @@ try:
# Test select filters
select_filters = [
{"name": "Method", "id": "method", "value": "all", "update_value": "123456"},
{"name": "State", "id": "state", "value": "all", "update_value": "123456"},
{"name": "Method", "id": "method", "value": "all"},
{"name": "State", "id": "state", "value": "all"},
]
verify_select_filters(DRIVER, "services", select_filters)
for item in select_filters:
DRIVER.execute_script(f"""document.querySelector('[data-services-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
log_info("Filters working as expected, trying to delete app2.example.com ...")

View file

@ -161,23 +161,3 @@ def wait_for_service(service: str = "www.example.com"):
retries += 1
log_warning(f"Waiting for {service} to be ready, retrying in 5s ...")
sleep(5)
# We replace value by non existing one and click on button
# If elements are hidden, it means script is working
# Example filter_items: [ {"name" : "Success state", "id" : "success", "value" : "all", "update_value" : "123456"}]
def verify_select_filters(driver, page_name: str, filter_items: list):
for item in filter_items:
# Get a select filter, change value and click to get no match
# Verify that elements are all hidden
# If not return false, else reset and send true
set_el = driver.execute_script(f"""const select{item["id"]} = document.querySelector('[data-{page_name}-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]');""")
log_info("Create variable")
update_el_val = driver.execute_script(f"""if(!select{item["id"]}){{ return false }};select{item["id"]}.setAttribute('value', '{item["update_value"]}');select{item["id"]}.click();""")
log_info("Update value")
check_el = driver.execute_script(f"""const select{item["id"]}Match = document.querySelectorAll('[data-{page_name}-list-item][class*="hidden"]');if (select{item["id"]}Match.length === 0){{ return false }};""")
log_info("Check if elements are hidden")
reset_el = driver.execute_script(f"""select{item["id"]}.setAttribute('value', '{item["value"]}');select{item["id"]}.click();""")
log_info("Reset value")
sleep(0.1)