Skip to content

Commit

Permalink
TE-1199 / 13.0 / Switch AD test to AD03 and added code to leave if AD…
Browse files Browse the repository at this point in the history
… test fails (#9068)

* Changed workgroup to AD03 for HA and non HA UI test

* Adding code to leave properly AD on failure

* Fixed get_state API call

* Change back AD02 to AD03.

* fixed bad logic with code to leave AD HA UI test

* removed os from test_NAS_T0904.py
  • Loading branch information
ericbsd authored Oct 26, 2023
1 parent d504629 commit eaaa61a
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 34 deletions.
29 changes: 14 additions & 15 deletions tests/bdd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
import xpaths
from configparser import ConfigParser
from function import get, post
from platform import system
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
Expand Down Expand Up @@ -37,6 +38,7 @@ def nas_ip():
elif os.path.exists('config.cfg'):
configs = ConfigParser()
configs.read('config.cfg')
os.environ["nas_ip"] = configs['NAS_CONFIG']['ip']
return configs['NAS_CONFIG']['ip']
else:
return 'none'
Expand All @@ -49,6 +51,7 @@ def root_password():
elif os.path.exists('config.cfg'):
configs = ConfigParser()
configs.read('config.cfg')
os.environ["nas_password"] = configs['NAS_CONFIG']['password']
return configs['NAS_CONFIG']['password']
else:
return 'none'
Expand Down Expand Up @@ -162,7 +165,7 @@ def pytest_runtest_makereport(item):
if handle != initial_tab:
web_driver.close()
web_driver.switch_to.window(initial_tab)
if 'T1010' in screenshot_name or 'T0933' in screenshot_name:
if 'T1010' in screenshot_name or 'T0933' in screenshot_name or 'T0939.' in screenshot_name:
disable_active_directory()
elif 'T1013' in screenshot_name or 'T0940' in screenshot_name:
disable_ldap()
Expand Down Expand Up @@ -257,20 +260,16 @@ def enable_failover():


def disable_active_directory():
wait_on_element(7, '//mat-list-item[@ix-auto="option__Directory Services"]', 'clickable')
web_driver.find_element_by_xpath('//mat-list-item[@ix-auto="option__Directory Services"]').click()
wait_on_element(7, '//mat-list-item[@ix-auto="option__Active Directory"]', 'clickable')
web_driver.find_element_by_xpath('//mat-list-item[@ix-auto="option__Active Directory"]').click()
assert wait_on_element(5, '//li[span/a/text()="Active Directory"]')
assert wait_on_element(5, '//h4[contains(text(),"Domain Credentials")]')
wait_on_element(5, '//mat-checkbox[@ix-auto="checkbox__Enable (requires password or Kerberos principal)"]', 'clickable')
value_exist = attribute_value_exist('//mat-checkbox[@ix-auto="checkbox__Enable (requires password or Kerberos principal)"]', 'class', 'mat-checkbox-checked')
if value_exist:
web_driver.find_element_by_xpath('//mat-checkbox[@ix-auto="checkbox__Enable (requires password or Kerberos principal)"]').click()
wait_on_element(7, '//button[@ix-auto="button__SAVE"]', 'clickable')
web_driver.find_element_by_xpath('//button[@ix-auto="button__SAVE"]').click()
assert wait_on_element_disappear(60, '//h6[contains(.,"Please wait")]')
assert wait_on_element(7, '//div[contains(.,"Settings saved.")]')
if 'ad_user' in os.environ and 'ad_password' in os.environ:
results = get(os.environ.get("nas_ip"), '/activedirectory/get_state/', ('root', os.environ.get("nas_password")))
assert results.status_code == 200, results.text
if results.json() != 'DISABLED':
payload = {
"username": os.environ.get("ad_user"),
"password": os.environ.get("ad_password")
}
results = post(os.environ.get("nas_ip"), "/activedirectory/leave/", ('root', os.environ.get("nas_password")), payload)
assert results.status_code == 200, results.text


def disable_ldap():
Expand Down
7 changes: 7 additions & 0 deletions tests/bdd/core/test_NAS_T1003.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding=utf-8
"""Core UI feature tests."""

import os
import time
import reusableSeleniumCode as rsc
import xpaths
Expand All @@ -18,6 +19,10 @@
parsers
)

import pytest

pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1003.feature', 'Setup AD and verify it is working')
def test_setup_acl_and_verify_it_is_working(driver):
Expand Down Expand Up @@ -111,6 +116,8 @@ def the_domain_credentials_page_should_open(driver):
@then(parsers.parse('input Domain name "{ad_domain}", Account name "{ad_user}", Password "{ad_password}"'))
def input_domain_name_account_name_password(driver, ad_domain, ad_user, ad_password):
"""input Domain name "ad_domain", Account name "ad_user", Password "ad_password"."""
os.environ["ad_user"] = ad_user
os.environ["ad_password"] = ad_password
assert wait_on_element(driver, 7, '//input[@ix-auto="input__Domain Name"]', 'clickable')
assert wait_on_element(driver, 7, '//input[@ix-auto="input__Domain Account Name"]', 'clickable')
assert wait_on_element(driver, 7, '//input[@ix-auto="input__Domain Account Password"]', 'clickable')
Expand Down
3 changes: 3 additions & 0 deletions tests/bdd/core/test_NAS_T1004.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
when,
parsers
)
import pytest

pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1004.feature', 'Create an Active Directory dataset on a system dataset')
Expand Down
3 changes: 3 additions & 0 deletions tests/bdd/core/test_NAS_T1006.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
when,
parsers
)
import pytest

pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1006.feature', 'Create an Active Directory dataset on the tank pool')
Expand Down
5 changes: 4 additions & 1 deletion tests/bdd/core/test_NAS_T1007.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
when,
parsers
)
import pytest

pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1007.feature', 'Create an smb share with the tank AD permission dataset')
Expand Down Expand Up @@ -151,7 +154,7 @@ def click_on_the_smb_start_automatically_checkbox(driver):
def send_a_file_to_the_share_with_ip_tanksmbshare_and_user_password(driver, nas_ip, smbname, user, password):
"""send a file to the share with ip/"tanksmbshare" and "user"%"password"."""
run_cmd('touch testfile.txt')
results = run_cmd(f'smbclient //{nas_ip}/{smbname} -W AD02 -U {user}%{password} -c "put testfile.txt testfile.txt"')
results = run_cmd(f'smbclient //{nas_ip}/{smbname} -W AD03 -U {user}%{password} -c "put testfile.txt testfile.txt"')
time.sleep(1)
run_cmd('rm testfile.txt')
assert results['result'], results['output']
Expand Down
8 changes: 7 additions & 1 deletion tests/bdd/core/test_NAS_T1010.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding=utf-8
"""Core UI feature tests."""

import os
import time
import reusableSeleniumCode as rsc
import xpaths
Expand All @@ -19,6 +20,9 @@
when,
parsers
)
import pytest

pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1010.feature', 'Create an smb share with the system AD permission dataset')
Expand Down Expand Up @@ -150,8 +154,10 @@ def click_on_the_smb_start_automatically_checkbox(driver):
@then(parsers.parse('send a file to the share with ip/"{smbname}" and "{ad_user}"%"{ad_password}"'))
def send_a_file_to_the_share_with_ip_tanksmbshare_and_user_password(driver, nas_ip, smbname, ad_user, ad_password):
"""send a file to the share with ip/"tanksmbshare" and "user"%"password"."""
os.environ["ad_user"] = ad_user
os.environ["ad_password"] = ad_password
run_cmd('touch testfile.txt')
results = run_cmd(f'smbclient //{nas_ip}/{smbname} -W AD02 -U {ad_user}%{ad_password} -c "put testfile.txt testfile.txt"')
results = run_cmd(f'smbclient //{nas_ip}/{smbname} -W AD03 -U {ad_user}%{ad_password} -c "put testfile.txt testfile.txt"')
time.sleep(1)
run_cmd('rm testfile.txt')
assert results['result'], results['output']
Expand Down
2 changes: 0 additions & 2 deletions tests/bdd/core/test_NAS_T1080.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
then,
when,
)
import pytest
pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1080.feature', 'Verify that a pool can be encrypted, locked and unlocked with a passphrase')
Expand Down
2 changes: 0 additions & 2 deletions tests/bdd/core/test_NAS_T1081.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
then,
when,
)
import pytest
pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1081.feature', 'Verify dataset Encryption Inheritance')
Expand Down
2 changes: 0 additions & 2 deletions tests/bdd/core/test_NAS_T1083.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
then,
when,
)
import pytest
pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1083.feature', 'Verify encrypted dataset and pool can be delete')
Expand Down
2 changes: 0 additions & 2 deletions tests/bdd/core/test_NAS_T1085.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
then,
when,
)
import pytest
pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1085.feature', 'Verify that changing an encryption key format to PASSPHRASE functions')
Expand Down
2 changes: 0 additions & 2 deletions tests/bdd/core/test_NAS_T1086.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
then,
when,
)
import pytest
pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1086.feature', 'Verify the ZFS Encryption Options function')
Expand Down
2 changes: 0 additions & 2 deletions tests/bdd/core/test_NAS_T1088.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
then,
when,
)
import pytest
pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1088.feature', 'Verify an exception is raised when entering the wrong passphrase for an encrypted pool')
Expand Down
Empty file.
Empty file.
2 changes: 0 additions & 2 deletions tests/bdd/core/test_NAS_T1142.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
when,
parsers
)
import pytest
pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1142.feature', 'Verify Backblaze B2 credentials can be added')
Expand Down
2 changes: 0 additions & 2 deletions tests/bdd/core/test_NAS_T1143.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
when,
parsers
)
import pytest
pytestmark = [pytest.mark.debug_test]


@scenario('features/NAS-T1143.feature', 'Verify Backblaze B2 Cloud Sync task works')
Expand Down
5 changes: 5 additions & 0 deletions tests/bdd/ha-bhyve02/test_NAS_T0933.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding=utf-8
"""High Availability (tn-bhyve02) feature tests."""

import os
import pytest
import reusableSeleniumCode as rsc
import xpaths
Expand Down Expand Up @@ -34,6 +35,7 @@ def the_browser_is_open_navigate_to_nas_url(driver, nas_url):
"""the browser is open navigate to "{nas_url}"."""
global host
host = nas_url
os.environ["nas_ip"] = nas_url
if nas_url not in driver.current_url:
driver.get(f"http://{nas_url}/ui/dashboard/")
time.sleep(1)
Expand All @@ -44,6 +46,7 @@ def if_login_page_appear_enter_root_and_password(driver, user, password):
"""If login page appear enter "{user}" and "{password}"."""
global passwd
passwd = password
os.environ["nas_password"] = password
if not is_element_present(driver, '//mat-list-item[@ix-auto="option__Dashboard"]'):
assert wait_on_element(driver, 10, xpaths.login.user_input)
driver.find_element_by_xpath(xpaths.login.user_input).clear()
Expand Down Expand Up @@ -128,6 +131,8 @@ def the_domain_credentials_page_should_open(driver):
@then(parsers.parse('Input Domain name "{ad_domain}", Account name "{ad_user}", Password "{ad_password}"'))
def input_domain_name_ad_domain_account_name_ad_user_password_ad_pasword(driver, ad_domain, ad_user, ad_password):
"""Input Domain name "{ad_domain}", Account name "{ad_user}", Password "ad_password"."""
os.environ["ad_user"] = ad_user
os.environ["ad_password"] = ad_password
assert wait_on_element(driver, 7, '//input[@ix-auto="input__Domain Name"]')
driver.find_element_by_xpath('//input[@ix-auto="input__Domain Name"]').clear()
driver.find_element_by_xpath('//input[@ix-auto="input__Domain Name"]').send_keys(ad_domain)
Expand Down
2 changes: 1 addition & 1 deletion tests/bdd/ha-bhyve02/test_NAS_T0939.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def click_on_smb_start_automatically_checkbox(driver):
def send_a_file_to_the_share_with_nas_url_smbname_and_user_password(driver, nas_url, smbname, ad_user, ad_password):
"""Send a file the share with "nas_url"/"smbname" and "user"%"password"."""
run_cmd('touch testfile.txt')
results = run_cmd(f'smbclient //{nas_url}/{smbname} -W AD02 -U {ad_user}%{ad_password} -c "put testfile.txt testfile.txt"')
results = run_cmd(f'smbclient //{nas_url}/{smbname} -W AD03 -U {ad_user}%{ad_password} -c "put testfile.txt testfile.txt"')
time.sleep(1)
run_cmd('rm testfile.txt')
assert results['result'], results['output']
Expand Down

0 comments on commit eaaa61a

Please sign in to comment.