Skip to content

Commit 7d1b622

Browse files
committed
ISSUE-338: make login display safe + test config update
1 parent a24288c commit 7d1b622

File tree

7 files changed

+44
-25
lines changed

7 files changed

+44
-25
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ jobs:
7979
cp -fv tests/ci/config.php public_html/lists/config/config.php
8080
mkdir -p output/screenshots
8181
mkdir -p build/mails
82+
chmod -R 777 output/screenshots build/mails
8283
./bin/start-selenium > output/selenium.log 2>&1 &
8384
sleep 5
8485
sudo php -S 0.0.0.0:80 -t public_html > /dev/null 2>&1 &

public_html/lists/admin/login.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,18 @@ function renderSSO()
5353
echo '<div style="display: flex; justify-content: space-around; align-items: center;">';
5454

5555
foreach ($GLOBALS['ssoplugin'] as $plugin) {
56-
$ssoUrl = $GLOBALS['plugins'][$plugin]->autUrl;
57-
$buttonText = 'Login with ' . $GLOBALS['plugins'][$plugin]->settings['display_name']['value'];
56+
if (isset($GLOBALS['plugins'][$plugin])) {
57+
$pluginInstance = $GLOBALS['plugins'][$plugin];
58+
$ssoUrl = $pluginInstance->autUrl;
59+
$buttonText = 'Login with ' . getConfig($pluginInstance->name);
5860

59-
echo '<a href="?' . $ssoUrl . '"
60-
style="display: inline-block; padding: 8px 15px; background-color: #3c3c3c; color: #fff;
61-
text-decoration: none; border-radius: 5px; font-size: 16px; text-align: center;
62-
min-width: 120px;">
63-
' . $buttonText . '
64-
</a>';
61+
echo '<a href="?' . $ssoUrl . '"
62+
style="display: inline-block; padding: 8px 15px; background-color: #3c3c3c; color: #fff;
63+
text-decoration: none; border-radius: 5px; font-size: 16px; text-align: center;
64+
min-width: 120px;">
65+
' . $buttonText . '
66+
</a>';
67+
}
6568
}
6669

6770
echo '</div>';

tests/ci/behat.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ default:
5454
selenium2:
5555
browser: "firefox"
5656
wd_host: http://127.0.0.1:4444/wd/hub
57-
FailAid\Extension:
57+
FailAid\Extension:
5858
screenshot:
5959
directory: ./output/screenshots/
6060
mode: default
@@ -65,7 +65,7 @@ default:
6565
image_drivers:
6666
local:
6767
screenshot_directory: output/screenshots
68-
clear_screenshot_directory: true
68+
clear_screenshot_directory: true
6969

7070
chrome:
7171
extensions:

tests/features/bootstrap/FeatureContext.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
<?php
22

3-
use Behat\Behat\Context\Context;
43

54
use Behat\Mink\Exception\ExpectationException;
65
use Behat\MinkExtension\Context\MinkContext;
7-
#use Behat\MinkExtension\Context\RawMinkContext;
8-
9-
//
10-
// Require 3rd-party libraries here:
11-
//
12-
// require_once 'PHPUnit/Autoload.php';
13-
// require_once 'PHPUnit/Framework/Assert/Functions.php';
14-
//
156

167
/**
178
* Features context.
@@ -107,7 +98,7 @@ public function spins($closure, $tries = 10)
10798
$closure();
10899

109100
return;
110-
} catch (\Exception $e) {
101+
} catch (Exception $e) {
111102
if ($i == $tries) {
112103
throw $e;
113104
}
@@ -179,7 +170,7 @@ public function isLoggedIn($throwsException = false)
179170
{
180171
$retVal = $this->token != null;
181172
if(!$retVal && $throwsException){
182-
throw new \Exception('Not logged in yet');
173+
throw new Exception('Not logged in yet');
183174
}
184175
return $retVal;
185176
}
@@ -325,4 +316,28 @@ public function iConfirmThePopup()
325316
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
326317
}
327318

319+
/**
320+
* @Then I must see :text
321+
*/
322+
public function iMustSee($text)
323+
{
324+
$maxAttempts = 3;
325+
$waitTimeMs = 1000;
326+
$this->getSession()->wait(5000, "document.readyState === 'complete'");
327+
328+
for ($attempt = 1; $attempt <= $maxAttempts; $attempt++) {
329+
try {
330+
$this->assertSession()->pageTextContains($this->fixStepArgument($text));
331+
return;
332+
} catch (\WebDriver\Exception\StaleElementReference $e) {
333+
// Handle Selenium stale element exception, retry
334+
} catch (\Behat\Mink\Exception\ResponseTextException $e) {
335+
// Handle Mink text assertion failure, retry
336+
}
337+
338+
usleep($waitTimeMs * 1000);
339+
}
340+
341+
throw new Exception(sprintf("Text '%s' not found after %d attempts.", $text, $maxAttempts));
342+
}
328343
}

tests/features/getting-started/login.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ Feature: Login
88
When I fill in "login" with a valid username
99
And I fill in "password" with a valid password
1010
And I press "Continue"
11-
Then I should see "Start or continue a campaign"
11+
Then I must see "Start or continue a campaign"
1212

1313
Scenario: Login with bad credentials
1414
Given I am on "/lists/admin/"
1515
When I fill in "login" with "no-user"
1616
And I fill in "password" with "no-password"
1717
And I press "Continue"
18-
Then I should see "Incorrect password"
18+
Then I must see "Incorrect password"
1919

2020
# Scenario: Login with only a username
2121
# Given I am on "/lists/admin/"

tests/features/getting-started/menu.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Feature: Navigate the app using the menu
77

88
Scenario Outline: Use main menu navigation links
99
Given I have logged in as an administrator
10-
Then I should see "<Pagename>"
10+
Then I must see "<Pagename>"
1111
Examples:
1212
| Pagename |
1313
| dashboard |

tests/features/managing-campaigns/newcampaign.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Feature: Create new campaign
3838
And I follow "Start a new campaign"
3939
When I follow "Lists"
4040
# Try with and without the colon
41-
Then I should see "Please select the lists you want to send your campaign to:"
41+
Then I must see "Please select the lists you want to send your campaign to:"
4242
And the "targetlist[all]" checkbox should not be checked
4343
And the "targetlist[allactive]" checkbox should not be checked
4444

0 commit comments

Comments
 (0)