Commit f698cf1d authored by Laurent's avatar Laurent

add Koha with CAS tests

parent cc65466e
import {HTTPScenario} from './http-scenario';
abstract class KohaCASScenario extends HTTPScenario {
public constructor() {
super()
this
.expect({ url: 'http://ul.fr' },
{ content: this.frontPage() })
.then({ url: 'https://cas.ul.fr/cas/login?service=https%3A%2F%2Fcas.ul.fr%2Fcgi-bin%2Fkoha%2Fopac-user.pl' },
{ content: this.loginForm() })
}
public frontPage(): string {
return this._encapsulate('\
<a href="https://cas.ul.fr/cas/login?service=https%3A%2F%2Fcas.ul.fr%2Fcgi-bin%2Fkoha%2Fopac-user.pl">\
cliquez ici pour vous connecter\
</a>')
}
public abstract loginForm(): string;
public accountPage(): string {
return this._encapsulate('\
<div id="userdetails" class="maincontent">\
<h2>Bonjour Marco POLO </h2>\
</div>')
}
public accountInfoPage(): string {
return this._encapsulate('\
<form id="memberentry-form">\
<fieldset class="rows" id="memberentry_library">\
<legend id="library_legend">Site</legend>\
<ol>\
<li>\
<label for="borrower_cardnumber">Numéro carte de bibliothèque&nbsp;:</label>\
2987632\
</li>\
<li>\
<label>Date d\'expiration&nbsp;:</label>\
27/08/2020\
</li>\
</ol>\
</fieldset>\
<div class="row-fluid">\
<div class="span12">\
<fieldset class="rows" id="memberentry_identity">\
<legend id="identity_legend">Identité</legend>\
<ol>\
<li>\
<label for="borrower_surname" class="required" aria-required="true">Nom de famille&nbsp;:</label>\
<input id="borrower_surname" name="borrower_surname" value="POLO" type="text">\
<span class="required" aria-required="true">Obligatoire</span>\
</li>\
<li>\
<label for="borrower_firstname" class="required" aria-required="true">Prénom&nbsp;:</label>\
<input id="borrower_firstname" name="borrower_firstname" value="Marco" type="text">\
<span class="required" aria-required="true">Obligatoire</span>\
</li>\
</ol>\
</fieldset>\
</div>\
</div>\
</form>')
}
}
export class KohaSignInCASUL2 extends KohaCASScenario {
public constructor() {
super()
this
.expect(
{
content: 'username=marco&password=polo&execution=e1s1&_eventId=submit&lt=LT-728899-oxKAugIlDkh6gp6wclE9ixoD3zA7E3&submit=CONNEXION',
dontFollowRedirects: true,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'POST',
url: 'https://cas.ul.fr/cas/login?service=https%3A%2F%2Fcas.ul.fr%2Fcgi-bin%2Fkoha%2Fopac-user.pl'
},
{
headers: { Location: 'https://ul.fr/cgi-bin/koha/opac-user.pl?ticket=ST-686-KzTBzmuP156d0m65yHR8tYmqso8-cas.ul.fr' },
statusCode: 302
})
.expect(
{ url: 'https://ul.fr/cgi-bin/koha/opac-user.pl?ticket=ST-686-KzTBzmuP156d0m65yHR8tYmqso8-cas.ul.fr' },
{ content: this.accountPage() }
)
.expect(
{ url: 'http://ul.fr/cgi-bin/koha/opac-memberentry.pl' },
{ content: this.accountInfoPage() })
}
public loginForm(): string {
return this._encapsulate('\
<form action="/cas/login;jsessionid=FB2173A0F568A1AD535E98E783F15895?service=https%3A%2F%2Ful.fr%2Fcgi-bin%2Fkoha%2Fopac-user.pl" method="post">\
<input id="username" name="username">\
<input id="password" name="password">\
<input name="lt" value="LT-728899-oxKAugIlDkh6gp6wclE9ixoD3zA7E3" type="hidden">\
<input name="execution" value="e1s1" type="hidden">\
<input name="_eventId" value="submit" type="hidden">\
<input class="btn-submit" name="submit" value="CONNEXION" type="submit">\
<input class="btn-reset" name="reset" value="EFFACER" type="reset">\
</form>')
}
}
export class KohaSignInCASUL3 extends KohaCASScenario {
public constructor() {
super()
this
.expect(
{
content: 'username=marco&password=polo&execution=e1s1&_eventId=submit&lt=&submit=SE%20CONNECTER',
dontFollowRedirects: true,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'POST',
url: 'https://cas.ul.fr/cas/login?service=https%3A%2F%2Fcas.ul.fr%2Fcgi-bin%2Fkoha%2Fopac-user.pl'
},
{
headers: { Location: 'https://ul.fr/cgi-bin/koha/opac-user.pl?ticket=ST-686-KzTBzmuP156d0m65yHR8tYmqso8-cas.ul.fr' },
statusCode: 302
})
.expect(
{ url: 'https://ul.fr/cgi-bin/koha/opac-user.pl?ticket=ST-686-KzTBzmuP156d0m65yHR8tYmqso8-cas.ul.fr' },
{ content: this.preAccountPage() } )
.expect(
{ url: 'https://cas.ul.fr/cas/login?service=http%3A%2F%2Ful.fr%2Fcgi-bin%2Fkoha%2Fopac-user.pl' },
{ content: this.accountPage() })
.expect(
{ url: 'http://ul.fr/cgi-bin/koha/opac-memberentry.pl' },
{ content: this.accountInfoPage() })
}
public loginForm(): string {
return this._encapsulate('\
<form method="post">\
<input id="username" name="username" value="" type="text">\
<input id="password" name="password" value="" type="password">\
<input name="warn" value="true" type="checkbox"><label for="warn">\
<input name="execution" value="e1s1" type="hidden">\
<input name="_eventId" value="submit" type="hidden">\
<input name="geolocation" type="hidden">\
<input name="submit" value="SE CONNECTER" type="submit">\
<input class="btn btn-default" name="reset" value="EFFACER" type="reset">\
</form>')
}
public preAccountPage(): string {
return this._encapsulate('\
<a href="https://cas.ul.fr/cas/login?service=http%3A%2F%2Ful.fr%2Fcgi-bin%2Fkoha%2Fopac-user.pl">\
cliquez ici pour vous connecter\
</a>')
}
}
declare var describe, expect, it, before, beforeEach, chai: any
import {Account, Database, WrongLoginPassword} from '../../models/'
import {KohaCas} from '../../models/portal/koha-cas'
import {KohaSignInCASUL2,
KohaSignInCASUL3} from './koha-cas-fixtures'
describe('Account on Koha', () => {
let account: Account
let db: Database
beforeEach( () => {
db = Database.open('testdb').clear()
account = (new Account())
.setUrl('http://ul.fr')
.setCredentials({login: 'marco',
password: 'polo',
portal: 'koha-cas'})
db.save(account)
})
it('should sign in with CAS UL2', () => {
let http = new KohaSignInCASUL2();
return new KohaCas().setHTTP(http).signIn(account).then(() => {
expect(account.label).to.equals('Marco POLO')
})
})
it('should sign in with CAS UL3', () => {
let http = new KohaSignInCASUL3();
return new KohaCas().setHTTP(http).signIn(account).then(() => {
expect(account.label).to.equals('Marco POLO')
})
})
})
declare var expect: any;
import {HTTPScenario} from './http-scenario';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment