Skip to content

Commit 5dd4109

Browse files
Configure fakeportal with tls
1 parent ac70562 commit 5dd4109

File tree

15 files changed

+111
-24
lines changed

15 files changed

+111
-24
lines changed

selenium/bin/components/fakeportal

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ ensure_fakeportal() {
1515
}
1616

1717
init_fakeportal() {
18-
FAKEPORTAL_URL=${FAKEPORTAL_URL:-http://fakeportal:3000}
18+
FAKEPORTAL_URL=${FAKEPORTAL_URL:-https://fakeportal:3000}
19+
FAKEPORTAL_CONFIG_PATH=${FAKEPORTAL_CONFIG_PATH:-oauth/fakeportal}
20+
FAKEPORTAL_CONFIG_DIR=$(realpath ${TEST_DIR}/${FAKEPORTAL_CONFIG_PATH})
21+
1922
FAKEPORTAL_DIR=${SCRIPT}/../../fakeportal
2023
CLIENT_ID="${CLIENT_ID:-rabbit_idp_user}"
2124
CLIENT_SECRET="${CLIENT_SECRET:-rabbit_idp_user}"
@@ -32,6 +35,9 @@ init_fakeportal() {
3235
print "> CLIENT_ID: ${CLIENT_ID}"
3336
print "> CLIENT_SECRET: ${CLIENT_SECRET}"
3437
print "> RABBITMQ_URL: ${RABBITMQ_URL}"
38+
39+
generate-ca-server-client-kpi fakeportal $FAKEPORTAL_CONFIG_DIR
40+
3541
}
3642
start_fakeportal() {
3743
begin "Starting fakeportal ..."
@@ -40,6 +46,10 @@ start_fakeportal() {
4046
kill_container_if_exist fakeportal
4147
mocha_test_tag=($(md5sum $SELENIUM_ROOT_FOLDER/package.json))
4248

49+
MOUNT_FAKEPORTAL_CONF_DIR=$CONF_DIR/fakeportal
50+
mkdir -p $MOUNT_FAKEPORTAL_CONF_DIR
51+
cp ${FAKEPORTAL_CONFIG_DIR}/*.pem $MOUNT_FAKEPORTAL_CONF_DIR
52+
4353
docker run \
4454
--detach \
4555
--name fakeportal \
@@ -53,6 +63,7 @@ start_fakeportal() {
5363
--env CLIENT_SECRET="${CLIENT_SECRET}" \
5464
--env NODE_EXTRA_CA_CERTS=/etc/uaa/ca_uaa_certificate.pem \
5565
-v ${TEST_CONFIG_PATH}/uaa:/etc/uaa \
66+
-v ${MOUNT_FAKEPORTAL_CONF_DIR}:/etc/fakeportal \
5667
-v ${FAKEPORTAL_DIR}:/code/fakeportal \
5768
mocha-test:${mocha_test_tag} run fakeportal
5869

selenium/bin/suite_template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ wait_for_url_local() {
227227
url=$1
228228
max_retry=10
229229
counter=0
230-
until (curl -L -f -v $url >/dev/null 2>&1)
230+
until (curl -k -L -f -v $url >/dev/null 2>&1)
231231
do
232232
print "Waiting for $url to start (local)"
233233
sleep 5

selenium/fakeportal/app.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const express = require("express");
22
const app = express();
3+
const fs = require('fs');
4+
const https = require('https');
35
var path = require('path');
46
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
57

@@ -15,19 +17,36 @@ app.set('views', path.join(__dirname, 'views'));
1517
app.set('view engine', 'html');
1618

1719
app.get('/', function(req, res){
18-
let id = default_if_blank(req.query.client_id, client_id);
19-
let secret = default_if_blank(req.query.client_secret, client_secret);
20-
res.render('rabbitmq', {
21-
proxied_url: proxied_rabbitmq_url,
22-
url: rabbitmq_url.replace(/\/?$/, '/') + "login",
23-
name: rabbitmq_url + " for " + id,
24-
access_token: access_token(id, secret)
25-
});
26-
});
20+
let id = default_if_blank(req.query.client_id, client_id)
21+
let secret = default_if_blank(req.query.client_secret, client_secret)
22+
if (id == 'undefined' || secret == 'undefined') {
23+
res.render('unauthenticated')
24+
}else {
25+
res.render('rabbitmq', {
26+
proxied_url: proxied_rabbitmq_url,
27+
url: rabbitmq_url.replace(/\/?$/, '/') + "login",
28+
name: rabbitmq_url + " for " + id,
29+
access_token: access_token(id, secret)
30+
})
31+
}
32+
})
33+
2734
app.get('/favicon.ico', (req, res) => res.status(204));
2835

36+
app.get('/logout', function(req, res) {
37+
res.redirect( uaa_url + '/logout.do?redirect=' + req.protocol + '://' + req.get('host') + "/");
38+
})
39+
40+
https
41+
.createServer(
42+
{
43+
cert: fs.readFileSync('/etc/fakeportal/server_fakeportal_certificate.pem'),
44+
key: fs.readFileSync('/etc/fakeportal/server_fakeportal_key.pem')
45+
},
46+
app
47+
)
48+
.listen(port)
2949

30-
app.listen(port);
3150
console.log('Express started on port ' + port);
3251

3352
function default_if_blank(value, defaultValue) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<h1> FakePortal </h1>
2+
3+
<p>This is a portal used to test <b>Identity-Provider-based authentication</b>.
4+
This means users comes to RabbitMQ with a token already obtained without involving RabbitMQ
5+
management ui.
6+
</p>
7+
8+
<p>This is the state of the Portal when the user is not authenticated yet.</p>
9+
<p>To get the fakeportal fully authenticated, pass two request parameters:
10+
<ul>
11+
<li>client_id</li>
12+
<li>client_secret</li>
13+
</ul>
14+
These credentitals are used to get an access token from UAA and send it to
15+
RabbitMQ.
16+
</p>
17+
18+

selenium/suites/authnz-mgt/oauth-idp-initiated-with-uaa.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/oauth/with-idp-initiated
66
TEST_CONFIG_PATH=/oauth
7-
PROFILES="uaa idp-initiated uaa-oauth-provider fakeportal-mgt-oauth-provider"
7+
PROFILES="uaa uaa-oauth-provider idp-initiated fakeportal-mgt-oauth-provider"
88

99
source $SCRIPT/../../bin/suite_template $@
1010
runWith uaa fakeportal
11+
#runWith fakeportal
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export FAKEPORTAL_URL=http://fakeportal:3000
1+
export FAKEPORTAL_URL=https://fakeportal:3000
22
export RABBITMQ_HOST_FOR_FAKEPORTAL=${RABBITMQ_HOST}
33
export UAA_URL_FOR_FAKEPORTAL=https://uaa:8443
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export FAKEPORTAL_URL=http://localhost:3000
1+
export FAKEPORTAL_URL=https://fakeportal:3000
22
export RABBITMQ_HOST_FOR_FAKEPORTAL=localhost:15672
33
export UAA_URL_FOR_FAKEPORTAL=https://uaa:8443
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[ client_alt_names ]
2+
email.1 = rabbit_client@localhost
3+
URI.1 = rabbit_client_id_uri
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
management.oauth_initiated_logon_type = idp_initiated
2+
3+
auth_oauth2.end_session_endpoint = ${FAKEPORTAL_URL}/logout
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# uaa requires a secret in order to renew tokens
22
management.oauth_provider_url = ${UAA_URL}
3+
# uaa requires a secret in order to renew tokens
4+
management.oauth_client_secret = ${OAUTH_CLIENT_SECRET}

selenium/test/oauth/rabbitmq.uaa-oauth-provider.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# uaa requires a secret in order to renew tokens
2-
management.oauth_client_secret = ${OAUTH_CLIENT_SECRET}
31

42
# configure static signing keys and the oauth provider used by the plugin
53
auth_oauth2.default_key = ${OAUTH_SIGNING_KEY_ID}

selenium/test/oauth/with-idp-initiated-via-proxy/happy-login.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ const OverviewPage = require('../../pageobjects/OverviewPage')
88
describe('A user with a JWT token', function () {
99
let overview
1010
let captureScreen
11-
let token
12-
let fakePortal
13-
11+
1412
before(async function () {
1513
driver = buildDriver()
1614
overview = new OverviewPage(driver)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { By, Key, until, Builder } = require('selenium-webdriver')
2+
require('chromedriver')
3+
const assert = require('assert')
4+
const { buildDriver, goToHome, captureScreensFor, teardown, idpLoginPage } = require('../../utils')
5+
6+
const SSOHomePage = require('../../pageobjects/SSOHomePage')
7+
const OverviewPage = require('../../pageobjects/OverviewPage')
8+
9+
describe('When a logged in user', function () {
10+
let overview
11+
let homePage
12+
let captureScreen
13+
let idpLogin
14+
15+
before(async function () {
16+
driver = buildDriver()
17+
overview = new OverviewPage(driver)
18+
captureScreen = captureScreensFor(driver, __filename)
19+
await goToHome(driver);
20+
await overview.isLoaded()
21+
assert.equal(await overview.getUser(), 'User rabbit_idp_user')
22+
})
23+
24+
it('logs out', async function () {
25+
await homePage.clickToLogin()
26+
await idpLogin.login('rabbit_admin', 'rabbit_admin')
27+
await overview.isLoaded()
28+
await overview.logout()
29+
await homePage.isLoaded()
30+
31+
})
32+
33+
after(async function () {
34+
await teardown(driver, this, captureScreen)
35+
})
36+
})

selenium/test/oauth/with-idp-initiated/happy-login.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
const { By, Key, until, Builder } = require('selenium-webdriver')
22
require('chromedriver')
33
const assert = require('assert')
4-
const { buildDriver, goToLogin, goTo, tokenFor, captureScreensFor, teardown } = require('../../utils')
4+
const { buildDriver, captureScreensFor, teardown } = require('../../utils')
55

66
const OverviewPage = require('../../pageobjects/OverviewPage')
77
const FakePortalPage = require('../../pageobjects/FakePortalPage')
88

99
describe('A user with a JWT token', function () {
1010
let overview
1111
let captureScreen
12-
let token
1312
let fakePortal
1413

1514
before(async function () {

selenium/test/pageobjects/FakePortalPage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const { By, Key, until, Builder } = require('selenium-webdriver')
33
const BasePage = require('./BasePage')
44

55
const FORM = By.css('form#login_form')
6-
const FAKE_PORTAL_URL = process.env.FAKE_PORTAL_URL || 'http://localhost:3000'
6+
const FAKEPORTAL_URL = process.env.FAKEPORTAL_URL || 'https://localhost:3000'
77

88
module.exports = class FakePortalPage extends BasePage {
99
async isLoaded () {
1010
return this.waitForDisplayed(FORM)
1111
}
1212

1313
async goToHome(client_id = undefined, client_secret = undefined) {
14-
const url = new URL(FAKE_PORTAL_URL);
14+
const url = new URL(FAKEPORTAL_URL);
1515
if (typeof client_id !== 'undefined') url.searchParams.append("client_id", client_id);
1616
if (typeof client_secret !== 'undefined') url.searchParams.append("client_secret", client_secret);
1717
return this.driver.get(url.href);

0 commit comments

Comments
 (0)