test: migration from Python to JavaScript
parent
a14c456800
commit
2b101a87b8
|
@ -77,9 +77,16 @@ class WebDAV {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
getEvent(resource, filename) {
|
getObject(resource, filename) {
|
||||||
|
let url
|
||||||
|
if (resource.match(/^http/))
|
||||||
|
url = resource
|
||||||
|
else
|
||||||
|
url = this.serverUrl + resource
|
||||||
|
if (filename)
|
||||||
|
url += filename
|
||||||
return davRequest({
|
return davRequest({
|
||||||
url: this.serverUrl + resource + filename,
|
url,
|
||||||
init: {
|
init: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
|
@ -380,7 +387,7 @@ class WebDAV {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
makeAddressBook(resource) {
|
makeCollection(resource) {
|
||||||
return makeCollection({
|
return makeCollection({
|
||||||
url: this.serverUrl + resource,
|
url: this.serverUrl + resource,
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
|
|
|
@ -143,8 +143,8 @@ class TestUtility {
|
||||||
return this._subscriptionOperation(resource, subscribers, 'unsubscribe')
|
return this._subscriptionOperation(resource, subscribers, 'unsubscribe')
|
||||||
}
|
}
|
||||||
|
|
||||||
versitDict(cal) {
|
versitDict(component) {
|
||||||
const comp = ICAL.Component.fromString(cal)
|
const comp = ICAL.Component.fromString(component)
|
||||||
let props = {}
|
let props = {}
|
||||||
|
|
||||||
for (const prop of comp.getAllProperties()) {
|
for (const prop of comp.getAllProperties()) {
|
||||||
|
@ -158,9 +158,9 @@ class TestUtility {
|
||||||
return props
|
return props
|
||||||
}
|
}
|
||||||
|
|
||||||
calendarsAreEqual(cal1, cal2) {
|
componentsAreEqual(comp1, comp2) {
|
||||||
const props1 = this.versitDict(cal1)
|
const props1 = this.versitDict(comp1)
|
||||||
const props2 = this.versitDict(cal2)
|
const props2 = this.versitDict(comp2)
|
||||||
for (const prop of Object.keys(props1)) {
|
for (const prop of Object.keys(props1)) {
|
||||||
if (props1[prop] != props2[prop]) {
|
if (props1[prop] != props2[prop]) {
|
||||||
console.debug(`Difference detected in ${prop}:\n\t1: ${props1[prop]}\n\t2: ${props2[prop]}`)
|
console.debug(`Difference detected in ${prop}:\n\t1: ${props1[prop]}\n\t2: ${props2[prop]}`)
|
||||||
|
|
|
@ -16,7 +16,7 @@ let icsName, icsList, vcalendar
|
||||||
describe('PreventInvitationsWhitelist user setting', function() {
|
describe('PreventInvitationsWhitelist user setting', function() {
|
||||||
|
|
||||||
const _getEvent = async function(client, calendarName, filename, expectedCode = 200) {
|
const _getEvent = async function(client, calendarName, filename, expectedCode = 200) {
|
||||||
const [{ status, headers, raw }] = await client.getEvent(calendarName, filename)
|
const [{ status, headers, raw }] = await client.getObject(calendarName, filename)
|
||||||
expect(status).toBe(expectedCode)
|
expect(status).toBe(expectedCode)
|
||||||
if (status <= 300)
|
if (status <= 300)
|
||||||
return new ICAL.Component(ICAL.parse(raw))
|
return new ICAL.Component(ICAL.parse(raw))
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe('create, read, modify, delete tasks for regular user', function() {
|
||||||
let icsList = []
|
let icsList = []
|
||||||
|
|
||||||
const _getEvent = async function(client, calendarName, filename, expectedCode = 200) {
|
const _getEvent = async function(client, calendarName, filename, expectedCode = 200) {
|
||||||
const [{ status, raw }] = await client.getEvent(calendarName, filename)
|
const [{ status, raw }] = await client.getObject(calendarName, filename)
|
||||||
expect(status).toBe(expectedCode)
|
expect(status).toBe(expectedCode)
|
||||||
if (status <= 300)
|
if (status <= 300)
|
||||||
return new ICAL.Component(ICAL.parse(raw))
|
return new ICAL.Component(ICAL.parse(raw))
|
||||||
|
|
|
@ -0,0 +1,130 @@
|
||||||
|
import config from '../lib/config'
|
||||||
|
import WebDAV from '../lib/WebDAV'
|
||||||
|
import TestUtility from '../lib/utilities'
|
||||||
|
|
||||||
|
import {
|
||||||
|
DAVNamespace,
|
||||||
|
DAVNamespaceShorthandMap,
|
||||||
|
davRequest
|
||||||
|
} from 'tsdav'
|
||||||
|
import { formatProps, getDAVAttribute } from 'tsdav/dist/util/requestHelpers';
|
||||||
|
|
||||||
|
const cards = {
|
||||||
|
'new.vcf': `BEGIN:VCARD
|
||||||
|
VERSION:3.0
|
||||||
|
PRODID:-//Inverse//Card Generator//EN
|
||||||
|
UID:NEWTESTCARD
|
||||||
|
N:New;Carte
|
||||||
|
FN:Carte 'new'
|
||||||
|
ORG:societe;service
|
||||||
|
NICKNAME:surnom
|
||||||
|
ADR;TYPE=work:adr2 societe;;adr societe;ville societe;etat soc;code soc;pays soc
|
||||||
|
ADR;TYPE=home:rue perso 2;;rue perso;ville perso;etat perso;code post perso;pays perso
|
||||||
|
TEL;TYPE=work:+1 514 123-3372
|
||||||
|
TEL;TYPE=home:tel dom
|
||||||
|
TEL;TYPE=cell:portable
|
||||||
|
TEL;TYPE=fax:fax
|
||||||
|
TEL;TYPE=pager:pager
|
||||||
|
X-MOZILLA-HTML:FALSE
|
||||||
|
EMAIL;TYPE=work:address.email@domaine.ca
|
||||||
|
EMAIL;TYPE=home:address.email@domaine2.com
|
||||||
|
URL;TYPE=home:web perso
|
||||||
|
TITLE:fonction
|
||||||
|
URL;TYPE=work:page soc
|
||||||
|
CUSTOM1:divers1
|
||||||
|
CUSTOM2:divers2
|
||||||
|
CUSTOM3:divers3
|
||||||
|
CUSTOM4:divers4
|
||||||
|
NOTE:Remarque
|
||||||
|
X-AIM:pseudo aim
|
||||||
|
END:VCARD`,
|
||||||
|
'new-modified.vcf': `BEGIN:VCARD
|
||||||
|
VERSION:3.0
|
||||||
|
PRODID:-//Inverse//Card Generator//EN
|
||||||
|
UID:NEWTESTCARD
|
||||||
|
N:New;Carte modifiee
|
||||||
|
FN:Carte modifiee 'new'
|
||||||
|
ORG:societe;service
|
||||||
|
NICKNAME:surnom
|
||||||
|
ADR;TYPE=work:adr2 societe;;adr societe;ville societe;etat soc;code soc;pays soc
|
||||||
|
ADR;TYPE=home:rue perso 2;;rue perso;ville perso;etat perso;code post perso;pays perso
|
||||||
|
TEL;TYPE=work:+1 514 123-3372
|
||||||
|
TEL;TYPE=home:tel dom
|
||||||
|
TEL;TYPE=cell:portable
|
||||||
|
TEL;TYPE=fax:fax
|
||||||
|
TEL;TYPE=pager:pager
|
||||||
|
X-MOZILLA-HTML:FALSE
|
||||||
|
EMAIL;TYPE=work:address.email@domaine.ca
|
||||||
|
EMAIL;TYPE=home:address.email@domaine2.com
|
||||||
|
URL;TYPE=home:web perso
|
||||||
|
TITLE:fonction
|
||||||
|
URL;TYPE=work:page soc
|
||||||
|
CUSTOM1:divers1
|
||||||
|
CUSTOM2:divers2
|
||||||
|
CUSTOM3:divers3
|
||||||
|
CUSTOM4:divers4
|
||||||
|
NOTE:Remarque
|
||||||
|
X-AIM:pseudo aim
|
||||||
|
END:VCARD`
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('CardDAV extensions', function() {
|
||||||
|
const webdav = new WebDAV(config.username, config.password)
|
||||||
|
const webdav_su = new WebDAV(config.superuser, config.superuser_password)
|
||||||
|
const utility = new TestUtility(webdav)
|
||||||
|
|
||||||
|
const resource = `/SOGo/dav/${config.username}/Contacts/test-carddav/`
|
||||||
|
|
||||||
|
const _putCard = async function(client, filename, expectedCode, realCard) {
|
||||||
|
const card = cards[realCard || filename]
|
||||||
|
if (!card)
|
||||||
|
throw new Error(`Card ${realCard || filename} is unknown`)
|
||||||
|
const response = await client.createVCard(resource, filename, card)
|
||||||
|
expect(response.status).toBe(expectedCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeAll(async function() {
|
||||||
|
await webdav.deleteObject(resource)
|
||||||
|
await webdav.makeCollection(resource)
|
||||||
|
for (let key of Object.keys(cards)) {
|
||||||
|
await _putCard(webdav, key, 201)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async function() {
|
||||||
|
await webdav_su.deleteObject(resource)
|
||||||
|
})
|
||||||
|
|
||||||
|
// https://datatracker.ietf.org/doc/html/rfc6352#section-8.7
|
||||||
|
fit("supports for addressbook-multiget", async function() {
|
||||||
|
const hrefs = Object.keys(cards).map(c => `${resource}${c}`)
|
||||||
|
const response = await davRequest({
|
||||||
|
url: webdav.serverUrl + resource,
|
||||||
|
init: {
|
||||||
|
method: 'REPORT',
|
||||||
|
namespace: DAVNamespaceShorthandMap[DAVNamespace.CARDDAV],
|
||||||
|
headers: { ...webdav.headers, depth: '0' },
|
||||||
|
body: {
|
||||||
|
'addressbook-multiget': {
|
||||||
|
_attributes: getDAVAttribute([
|
||||||
|
DAVNamespace.CARDDAV,
|
||||||
|
DAVNamespace.DAV
|
||||||
|
]),
|
||||||
|
[`${DAVNamespaceShorthandMap[DAVNamespace.DAV]}:prop`]: formatProps([{ name: 'address-data', namespace: DAVNamespace.CARDDAV }]),
|
||||||
|
[`${DAVNamespaceShorthandMap[DAVNamespace.DAV]}:href`]: hrefs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(response.length).toBe(2)
|
||||||
|
for (let r of response) {
|
||||||
|
const [name, ...rest] = r.href.split('/').reverse()
|
||||||
|
expect(r.status)
|
||||||
|
.withContext(`HTTP status code of addressbook-multiget`)
|
||||||
|
.toEqual(207)
|
||||||
|
expect(utility.componentsAreEqual(r.props.addressData, cards[name]))
|
||||||
|
.withContext(`Cards returned in addressbook-multiget`)
|
||||||
|
.toBe(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
|
@ -198,7 +198,7 @@ END:VCARD`
|
||||||
|
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
await webdav.deleteObject(resource)
|
await webdav.deleteObject(resource)
|
||||||
await webdav.makeAddressBook(resource)
|
await webdav.makeCollection(resource)
|
||||||
await _putCard(webdav, 'old.vcf', 201)
|
await _putCard(webdav, 'old.vcf', 201)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ END:VCALENDAR`
|
||||||
const _getEvent = async function(eventClass, isInvitation = false) {
|
const _getEvent = async function(eventClass, isInvitation = false) {
|
||||||
const iscClass = classToICSClass[eventClass].toLowerCase()
|
const iscClass = classToICSClass[eventClass].toLowerCase()
|
||||||
const filename = (isInvitation ? `invitation-${iscClass}` : iscClass) + '-event.ics'
|
const filename = (isInvitation ? `invitation-${iscClass}` : iscClass) + '-event.ics'
|
||||||
const [{ status, raw = '' }] = await webdav_subscriber.getEvent(resource, filename)
|
const [{ status, raw = '' }] = await webdav_subscriber.getObject(resource, filename)
|
||||||
|
|
||||||
if (status == 200)
|
if (status == 200)
|
||||||
return raw.replace(/\r\n/g,'\n')
|
return raw.replace(/\r\n/g,'\n')
|
||||||
|
@ -303,7 +303,7 @@ END:VCALENDAR`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const event = await _getEvent(eventClass, true)
|
const event = await _getEvent(eventClass, true)
|
||||||
expect(utility.calendarsAreEqual(expectedEvent, event))
|
expect(utility.componentsAreEqual(expectedEvent, event))
|
||||||
.withContext('Calendars of organizer and attendee are identical')
|
.withContext('Calendars of organizer and attendee are identical')
|
||||||
.toBe(true)
|
.toBe(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ END:VCALENDAR`
|
||||||
|
|
||||||
// 2. Read - GET
|
// 2. Read - GET
|
||||||
|
|
||||||
results = await webdav_su.getEvent(resource, filename)
|
results = await webdav_su.getObject(resource, filename)
|
||||||
expect(results.length).toBe(1)
|
expect(results.length).toBe(1)
|
||||||
expect(results[0].raw.replace(/\r\n/g,'\n')).toBe(event)
|
expect(results[0].raw.replace(/\r\n/g,'\n')).toBe(event)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue