Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ function get_oauth_settings() {
export function oauth_initialize_if_required(state = "index") {
let oauth = oauth_initialize(get_oauth_settings())
if (!oauth.enabled) return oauth;

switch (state) {
case 'login-callback':
oauth_completeLogin(); break;
case 'logout-callback':
oauth_completeLogout(); break;
default:
oauth = oauth_initiate(oauth);
if (has_auth_credentials(BASIC_AUTH_SCHEME)) {
break;
} else {
oauth = oauth_initiate(oauth);
}
}
return oauth;
}
Expand Down
14 changes: 11 additions & 3 deletions deps/rabbitmq_management/priv/www/js/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const LOGGED_IN = 'loggedIn'
const LOGIN_SESSION_TIMEOUT = "login_session_timeout"
const AUTH_RESOURCE = 'auth_resource'

const BASIC_AUTH_SCHEME = "Basic"
const BEARER_AUTH_SCHEME = "Bearer"


function set_auth_resource(resource) {
store_local_pref(AUTH_RESOURCE, resource)
}
Expand All @@ -24,9 +28,12 @@ function get_auth_resource() {
return get_local_pref(AUTH_RESOURCE)
}

function has_auth_credentials() {
return get_local_pref(CREDENTIALS) != undefined && get_local_pref(AUTH_SCHEME) != undefined &&
get_cookie_value(LOGGED_IN) != undefined
// When auth_scheme is undefined, matches any scheme for backwards compatibility.
function has_auth_credentials(auth_scheme) {
let authenticated =get_local_pref(CREDENTIALS) != undefined && get_local_pref(AUTH_SCHEME) != undefined &&
get_cookie_value(LOGGED_IN) != undefined;
return authenticated && (auth_scheme == undefined
|| auth_scheme == get_auth_scheme());
}
function get_auth_credentials() {
return get_local_pref(CREDENTIALS)
Expand Down Expand Up @@ -54,6 +61,7 @@ function set_auth(auth_scheme, credentials, validUntil) {
store_local_pref(AUTH_SCHEME, auth_scheme)
store_cookie_value_with_expiration(LOGGED_IN, "true", validUntil) // session marker
}

function authorization_header() {
if (has_auth_credentials()) {
return get_auth_scheme() + ' ' + get_auth_credentials();
Expand Down
5 changes: 2 additions & 3 deletions selenium/bin/components/fakeproxy
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ init_fakeproxy() {
CLIENT_ID="${CLIENT_ID:-rabbit_idp_user}"
CLIENT_SECRET="${CLIENT_SECRET:-rabbit_idp_user}"
RABBITMQ_HOST_FOR_FAKEPROXY=${RABBITMQ_HOST_FOR_FAKEPROXY:-rabbitmq:15672}
UAA_URL_FOR_FAKEPROXY=${UAA_URL_FOR_FAKEPROXY:-http://uaa:8080}

RABBITMQ_URL_FOR_FAKEPROXY=$(calculate_rabbitmq_url $RABBITMQ_HOST_FOR_FAKEPROXY)

print "> FAKEPROXY_URL: ${FAKEPROXY_URL}"
print "> UAA_URL: ${UAA_URL_FOR_FAKEPROXY}"
print "> IDP_TOKEN_ENDPOINT: ${IDP_TOKEN_ENDPOINT}"
print "> RABBITMQ_HOST_FOR_FAKEPROXY: ${RABBITMQ_HOST_FOR_FAKEPROXY}"
print "> CLIENT_ID: ${CLIENT_ID}"
print "> CLIENT_SECRET: ${CLIENT_SECRET}"
Expand All @@ -46,7 +45,7 @@ start_fakeproxy() {
--publish 9090:9090 \
--env PORT=9090 \
--env RABBITMQ_URL="${RABBITMQ_URL_FOR_FAKEPROXY}" \
--env UAA_URL="${UAA_URL_FOR_FAKEPROXY}" \
--env IDP_TOKEN_ENDPOINT="${IDP_TOKEN_ENDPOINT}" \
--env CLIENT_ID="${CLIENT_ID}" \
--env CLIENT_SECRET="${CLIENT_SECRET}" \
--env NODE_EXTRA_CA_CERTS=/etc/uaa/ca_uaa_certificate.pem \
Expand Down
6 changes: 3 additions & 3 deletions selenium/fakeportal/proxy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var http = require('http'),
httpProxy = require('http-proxy');
httpProxy = require('http-proxy');

const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest

const rabbitmq_url = process.env.RABBITMQ_URL || 'http://0.0.0.0:15672/';
const client_id = process.env.CLIENT_ID;
const client_secret = process.env.CLIENT_SECRET;
const uaa_url = process.env.UAA_URL;
const port = process.env.PORT;
const idp_token_endpoint = process.env.IDP_TOKEN_ENDPOINT;

//
// Create a proxy server with custom application logic
Expand Down Expand Up @@ -52,7 +52,7 @@ function default_if_blank(value, defaultValue) {

function access_token(id, secret) {
const req = new XMLHttpRequest();
const url = uaa_url + '/oauth/token';
const url = idp_token_endpoint;
const params = 'client_id=' + id +
'&client_secret=' + secret +
'&grant_type=client_credentials' +
Expand Down
8 changes: 7 additions & 1 deletion selenium/test/amqp.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ module.exports = {
resolve()
})
})
console.log("Opening amqp connection using " + JSON.stringify(connectionOptions))
log("Opening amqp connection using " + JSON.stringify(connectionOptions,
(key, value) => {
// Omit the private key from the log output.
if (key === "key") return undefined;
return value;
}
))

let connection = container.connect(connectionOptions)
let receiver = connection.open_receiver({
Expand Down
42 changes: 41 additions & 1 deletion selenium/test/oauth/with-basic-auth/happy-login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { By, Key, until, Builder } = require('selenium-webdriver')
require('chromedriver')
const assert = require('assert')
const { buildDriver, goToHome, captureScreensFor, teardown, idpLoginPage } = require('../../utils')
const { buildDriver, goToHome, captureScreensFor, teardown, idpLoginPage, log } = require('../../utils')

const SSOHomePage = require('../../pageobjects/SSOHomePage')
const OverviewPage = require('../../pageobjects/OverviewPage')
Expand Down Expand Up @@ -40,6 +40,46 @@ describe('An user with administrator tag', function () {
await overview.logout()
})

describe("and logged in via OAuth 2.0", function() {
before(async function() {
await homePage.clickToLogin()
await idpLogin.login('rabbit_admin', 'rabbit_admin')
if (!await overview.isLoaded()) {
throw new Error('Failed to login via OAuth 2.0')
}
})
it ('can reload page without being logged out', async function() {
log("About to refresh page")
await overview.refresh()
if (!await overview.isLoaded()) {
throw new Error('Failed to keep session opened')
}
})
after(async function () {
await overview.logout()
})
})

describe("and logged in via basic auth", function() {
before(async function() {
await homePage.toggleBasicAuthSection()
await homePage.basicAuthLogin('guest', 'guest')
if (!await overview.isLoaded()) {
throw new Error('Failed to login')
}
})
it ('can reload page without being logged out', async function() {
log("About to refresh page")
await overview.refresh()
if (!await overview.isLoaded()) {
throw new Error('Failed to keep session opened')
}
})
after(async function () {
await overview.logout()
})
})

after(async function () {
await teardown(driver, this, captureScreen)
})
Expand Down
14 changes: 0 additions & 14 deletions selenium/test/oauth/with-basic-auth/unauthorized.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@ describe('An user without management tag', function () {
assert.ok(!await homePage.isOAuth2SectionVisible())
})

describe("After clicking on logout button", function() {

before(async function () {
await homePage.clickToLogout()
})

it('should get redirected to home page again without error message', async function(){
const visible = await homePage.isWarningVisible()
assert.ok(!visible)
})

})


after(async function () {
await teardown(driver, this, captureScreen)
})
Expand Down
12 changes: 12 additions & 0 deletions selenium/test/oauth/with-idp-initiated-via-proxy/happy-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ describe('A user with a JWT token', function () {
assert.equal(await overview.getUser(), 'User rabbit_idp_user')
})


it ('can reload page without being logged out', async function() {
await goToHome(driver);
await overview.isLoaded();

await overview.refresh()
if (!await overview.isLoaded()) {
throw new Error('Failed to keep session opened')
}
})


after(async function () {
await teardown(driver, this, captureScreen)
})
Expand Down
14 changes: 14 additions & 0 deletions selenium/test/oauth/with-idp-initiated/happy-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ describe('A user with a JWT token', function () {
assert.equal(await overview.getUser(), 'User ' + username)
})

it ('can reload page without being logged out', async function() {
await fakePortal.goToHome(username, password)
if (!await fakePortal.isLoaded()) {
throw new Error('Failed to load fakePortal')
}
await fakePortal.login()
await overview.isLoaded()

await overview.refresh()
if (!await overview.isLoaded()) {
throw new Error('Failed to keep session opened')
}
})

after(async function () {
await teardown(driver, this, captureScreen)
})
Expand Down
3 changes: 2 additions & 1 deletion selenium/test/oauth/with-idp-initiated/logout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { By, Key, until, Builder } = require('selenium-webdriver')
require('chromedriver')
const assert = require('assert')
const { buildDriver, captureScreensFor, teardown } = require('../../utils')
const { buildDriver, captureScreensFor, teardown, delay } = require('../../utils')

const OverviewPage = require('../../pageobjects/OverviewPage')
const FakePortalPage = require('../../pageobjects/FakePortalPage')
Expand All @@ -28,6 +28,7 @@ describe('When a logged in user', function () {

it('logs out', async function () {
await overview.logout()
await delay(1500)
await fakePortal.isLoaded()
})

Expand Down
2 changes: 1 addition & 1 deletion selenium/test/pageobjects/BasePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ module.exports = class BasePage {
'Timed out after [timeout=' + this.timeout + ';polling=' + this.polling + '] awaiting till visible ' + element,
this.polling / 2)
}catch(error) {
console.log("isDisplayed failed due to " + error);
require('../utils.js').log("isDisplayed failed due to " + error);
return Promise.resolve(false);
}
}
Expand Down
6 changes: 3 additions & 3 deletions selenium/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CaptureScreenshot {
await fsp.mkdir(screenshotsSubDir)
}
const dest = path.join(screenshotsSubDir, name + '.png')
console.log("screenshot saved to " + dest)
module.exports.log("screenshot saved to " + dest)
await fsp.writeFile(dest, image, 'base64')
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ module.exports = {
const queryString = params.join('&');

const url = d.baseUrl + '/login?' + queryString;
console.log("Navigating to " + url);
module.exports.log("Navigating to " + url);
return d.driver.get(url);
},

Expand Down Expand Up @@ -307,7 +307,7 @@ module.exports = {
driver.executeScript('lambda-status=passed')
} else {
if (captureScreen != null) {
console.log("Teardown failed . capture...");
module.exports.log("Teardown failed . capture...");
await captureScreen.shot('after-failed');
}
driver.executeScript('lambda-status=failed')
Expand Down
Loading