Skip to content

Commit

Permalink
Test cases for bearer and confidential clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Oliveira committed May 20, 2017
1 parent 167fc17 commit 21d0007
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
55 changes: 54 additions & 1 deletion test/keycloak-connect-web-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test('Should login with admin credentials', t => {
});
})

test('Should be forbidden for invalid public key', t => {
test('Public client should be forbidden for invalid public key', t => {
let app = new NodeApp();
var client = getAdminHelper().createClient(Type.publicClient(app.port, 'app2'));

Expand All @@ -104,6 +104,59 @@ test('Should be forbidden for invalid public key', t => {
})
})

test('Confidential client should be forbidden for invalid public key', t => {
let app = new NodeApp();
var client = getAdminHelper().createClient(Type.confidential(app.port, 'app3'));

client.then((installation) => {
installation['realm-public-key'] = TestVector.wrongRealmPublicKey;
app.build(installation);

t.plan(2);
page.index(app.port);
page.output().getText().then(function(text) {
t.equal(text, 'Init Success (Not Authenticated)', 'User should not be authenticated');
})
page.logInButton().click();
page.body().getText().then(function (text) {
t.equal(text, 'Access denied', 'Message should be access denied');
t.end();
}).then(() => {
app.close();
}).catch((err) => {
t.fail('Test failed');
});
})
})

test('Bearer client should be forbidden for invalid public key', t => {
let app = new NodeApp();
var client = getAdminHelper().createClient(Type.bearerOnly(app.port, 'app4'));

client.then((installation) => {
installation['realm-public-key'] = TestVector.wrongRealmPublicKey;
app.build(installation);

t.plan(2);
page.index(app.port);
page.output().getText().then(function(text) {
t.equal(text, 'Init Success (Not Authenticated)', 'User should not be authenticated');
})
page.logInButton().click();
page.body().getText().then(function (text) {
t.equal(text, 'Access denied', 'Message should be access denied');
t.end();
}).then(() => {
app.close();
}).catch((err) => {
t.fail('Test failed');
});
})
})




test('teardown', t => {
app.close();
getAdminHelper().destroy('test-realm');
Expand Down
6 changes: 6 additions & 0 deletions test/utils/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ ConsolePage.prototype.events = function () {
return driver.findElement(By.id('events'));
};

ConsolePage.prototype.print = function () {
driver.getPageSource().then((page) => {
console.log(page);
});
};

ConsolePage.prototype.login = function (user, pass) {
waitForVisibleElement(By.id('username'), 100000);
var username = driver.findElement(By.id('username'));
Expand Down

0 comments on commit 21d0007

Please sign in to comment.