Skip to content

Commit dcae2c7

Browse files
Configure fakeportal with tls
1 parent 732568b commit dcae2c7

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}

0 commit comments

Comments
 (0)