From 2feee5f3a28b54343376942032253b46d7a30d50 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 2 Sep 2021 10:29:27 -0400 Subject: [PATCH] test: migration from Python to JavaScript --- Tests/lib/Preferences.js | 168 +++++++++++++++++++++ Tests/lib/utilities.js | 29 ++++ Tests/spec/CalDAVPreventInvitationsSpec.js | 166 ++++++++++++++++++++ Tests/spec/CalDAVSchedulingSpec.js | 89 ++++------- Tests/spec/HTTPPreferencesSpec.js | 18 +-- 5 files changed, 402 insertions(+), 68 deletions(-) create mode 100644 Tests/lib/Preferences.js create mode 100644 Tests/spec/CalDAVPreventInvitationsSpec.js diff --git a/Tests/lib/Preferences.js b/Tests/lib/Preferences.js new file mode 100644 index 000000000..43ba618cb --- /dev/null +++ b/Tests/lib/Preferences.js @@ -0,0 +1,168 @@ +import cookie from 'cookie' +import { fetch } from 'cross-fetch' +import config from './config' + +/** + * NOTE + * + * For this class to be used, make sure XSRF validation is disabled on the server. + * In sogo.conf, you must have: + * + * SOGoXSRFValidationEnabled = NO; + */ + +class Preferences { + constructor(un, pw) { + this.username = un + this.password = pw + this.serverUrl = `http://${config.hostname}:${config.port}` + this.cookie = null + this.preferences = null + } + + async getAuthCookie() { + if (!this.cookie) { + const resource = `/SOGo/connect` + const response = await fetch(this.serverUrl + resource, { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({userName: this.username, password: this.password}) + }) + const values = response.headers.get('set-cookie').split(/, /) + let authCookies = [] + for (let v of values) { + let c = cookie.parse(v) + for (let authCookie of ['0xHIGHFLYxSOGo', 'XSRF-TOKEN']) { + if (Object.keys(c).includes('0xHIGHFLYxSOGo')) { + authCookies.push(cookie.serialize(authCookie, c[authCookie])) + } + } + } + this.cookie = authCookies.join('; ') + } + return this.cookie + } + + async getDefaults() { + const resource = `/SOGo/so/${this.username}/jsonDefaults` + const authCookie = await this.getAuthCookie() + const response = await fetch(this.serverUrl + resource, { + method: 'GET', + headers: { + Cookie: authCookie, + ...this.headers + } + }) + if (response.status == 200) { + const defaults = await response.json() + return defaults + } + else + throw new Error(`Can't fetch defaults of user ${this.username}: ${response.status}`) + } + + async getSettings() { + const resource = `/SOGo/so/${this.username}/jsonSettings` + const authCookie = await this.getAuthCookie() + const response = await fetch(this.serverUrl + resource, { + method: 'GET', + headers: { + Cookie: authCookie, + ...this.headers + } + }) + if (response.status == 200) { + const settings = await response.json() + return settings + } + else + throw new Error(`Can't fetch settings of user ${this.username}: ${response.status}`) + } + + async loadPreferences() { + const defaults = await this.getDefaults() + const settings = await this.getSettings() + + this.preferences = { defaults, settings } + } + + findKey(obj, key) { + if (Object.keys(obj).includes(key)) { + return obj + } + for (let k of Object.keys(obj)) { + if (typeof obj[k] == 'object') { + let o = this.findKey(obj[k], key) + if (o !== null) + return o + } + } + return null + } + + async get(preference, withCache = true) { + if (!withCache || !this.preferences) + await this.loadPreferences() + + if (!preference) + return this.preferences // return everything + + const obj = this.findKey(this.preferences, preference) + if (obj) + return obj[preference] + else + return null + } + + async setNoSave(preference, value) { + if (!this.preferences) + await this.loadPreferences() + + const obj = this.findKey(this.preferences, preference) + if (obj == null) + throw new Error(`Can't find key ${preference} in preferences`) + + if (typeof value == 'undefined') + delete obj[preference] + else + obj[preference] = value + } + + async set(preference, value) { + await this.setNoSave(preference, value) + return await this.save() + } + + async setOrCreate(preference, value, paths = ['defaults']) { + if (!this.preferences) + await this.loadPreferences() + + let obj = this.findKey(this.preferences, preference) + if (obj == null) { + obj = this.preferences + for (let path of paths) { + if (typeof obj[path] == 'undefined') + obj[path] = {} + obj = obj[path] + } + } + obj[preference] = value + } + + async save() { + const resource = `/SOGo/so/${this.username}/Preferences/save` + const authCookie = await this.getAuthCookie() + const response = await fetch(this.serverUrl + resource, { + method: 'POST', + headers: { + Cookie: authCookie, + 'Content-Type': 'application/json', + ...this.headers + }, + body: JSON.stringify(this.preferences) + }) + return response + } +} + +export default Preferences \ No newline at end of file diff --git a/Tests/lib/utilities.js b/Tests/lib/utilities.js index 9c9b938bd..55e8d3f0f 100644 --- a/Tests/lib/utilities.js +++ b/Tests/lib/utilities.js @@ -170,6 +170,35 @@ class TestUtility { return true } + createDateTimeProperty(propertyName, dateObject = new Date()) { + let property = new ICAL.Property(propertyName) + property.setParameter('tzid', 'America/Toronto') + property.setValue(ICAL.Time.fromJSDate(dateObject)) + + return property + } + + createCalendar(summary = 'test event', uid = 'test', transp = 'OPAQUE') { + const vcalendar = new ICAL.Component('vcalendar') + const vevent = new ICAL.Component('vevent') + const now = new Date() + const later = new Date(now.getTime() + 1000*60*60) // event lasts one hour + + vcalendar.addSubcomponent(vevent) + vevent.addPropertyWithValue('uid', uid) + vevent.addPropertyWithValue('summary', summary) + vevent.addPropertyWithValue('transp', transp) + vevent.addProperty(this.createDateTimeProperty('dtstart', now)) + vevent.addProperty(this.createDateTimeProperty('dtend', later)) + vevent.addProperty(this.createDateTimeProperty('dtstamp', now)) + vevent.addProperty(this.createDateTimeProperty('last-modified', now)) + vevent.addProperty(this.createDateTimeProperty('created', now)) + vevent.addPropertyWithValue('class', 'PUBLIC') + vevent.addPropertyWithValue('sequence', '0') + + return vcalendar + } + } export default TestUtility \ No newline at end of file diff --git a/Tests/spec/CalDAVPreventInvitationsSpec.js b/Tests/spec/CalDAVPreventInvitationsSpec.js new file mode 100644 index 000000000..995d5131d --- /dev/null +++ b/Tests/spec/CalDAVPreventInvitationsSpec.js @@ -0,0 +1,166 @@ +import config from '../lib/config' +import WebDAV from '../lib/WebDAV' +import TestUtility from '../lib/utilities' +import Preferences from '../lib/Preferences' +import ICAL from 'ical.js' + +// preventInvitationsTest +// CalDAVSchedulingTest + +let prefs +let webdav, webdav_su, webdavAttendee1, webdavAttendee1Delegate +let utility, user, attendee1, attendee1Delegate +let userCalendar, attendee1Calendar, attendee1DelegateCalendar +let icsName, icsList, vcalendar + +describe('PreventInvitationsWhitelist user setting', function() { + + const _getEvent = async function(client, calendarName, filename, expectedCode = 200) { + const [{ status, headers, raw }] = await client.getEvent(calendarName, filename) + expect(status).toBe(expectedCode) + if (status <= 300) + return new ICAL.Component(ICAL.parse(raw)) + return false + } + + const _putEvent = async function(client, calendarName, filename, event, expectedCode = 201) { + const response = await client.createCalendarObject(calendarName, filename, event.toString()) + expect(response.status) + .withContext(`Create event ${calendarName}${filename}`) + .toBe(expectedCode) + return response + } + + const _addAttendee = async function(expectedCode = 204) { + let vevent, organizer, attendee + + // add attendee after event creation + icsName = 'test-add-attendee.ics' + icsList.push(icsName) + + await webdav.deleteObject(userCalendar + icsName) + await webdavAttendee1.deleteObject(attendee1Calendar + icsName) + + // 1. create an event in the organiser's calendar + vcalendar = utility.createCalendar('Test add attendee', 'test-add-attendee') + vevent = vcalendar.getFirstSubcomponent('vevent') + organizer = new ICAL.Property('organizer') + organizer.setParameter('cn', user.displayname) + organizer.setValue(user.email) + vevent.addProperty(organizer) + await _putEvent(webdav, userCalendar, icsName, vcalendar) + + // 2. add an attendee + vcalendar.addPropertyWithValue('method', 'REQUEST') + attendee = new ICAL.Property('attendee') + attendee.setParameter('cn', attendee1.displayname) + attendee.setParameter('rsvp', 'TRUE') + attendee.setParameter('partstat', 'NEEDS-ACTION') + attendee.setValue(attendee1.email) + vevent.addProperty(attendee) + await _putEvent(webdav, userCalendar, icsName, vcalendar, expectedCode) + + // NOTE: vcalendar and icsName are global for _verifyEvent + } + + const _verifyEvent = async function(expectedCode = 200) { + // 1. verify that the attendee has the event + const vcalendarAttendee = await _getEvent(webdavAttendee1, attendee1Calendar, icsName, expectedCode) + + // 2. make sure the received event match the original one + if (vcalendarAttendee) { + const veventAttendee = vcalendarAttendee.getFirstSubcomponent('vevent') + const vevent = vcalendar.getFirstSubcomponent('vevent') + const uidAttendee = veventAttendee.getFirstProperty('uid').getFirstValue() + const uid = vevent.getFirstProperty('uid').getFirstValue() + expect(uidAttendee) + .toEqual(uid) + } + } + + beforeAll(async function() { + prefs = new Preferences(config.attendee1_username, config.attendee1_password) + const calendarPrefs = prefs.get('Calendar') + if (!calendarPrefs.PreventInvitationsWhitelist) + calendarPrefs.PreventInvitationsWhitelist = {} + await prefs.set('PreventInvitationsWhitelist', {}) + if (!calendarPrefs.PreventInvitations) + calendarPrefs.PreventInvitations = 0 + await prefs.set('PreventInvitations', 0) + + webdav = new WebDAV(config.username, config.password) + webdav_su = new WebDAV(config.superuser, config.superuser_password) + webdavAttendee1 = new WebDAV(config.attendee1, config.attendee1_password) + webdavAttendee1Delegate = new WebDAV(config.attendee1_delegate_username, config.attendee1_delegate_password) + + utility = new TestUtility(webdav) + user = await utility.fetchUserInfo(config.username) + attendee1 = await utility.fetchUserInfo(config.attendee1) + attendee1Delegate = await utility.fetchUserInfo(config.attendee1_delegate) + + userCalendar = `/SOGo/dav/${config.username}/Calendar/personal/` + attendee1Calendar = `/SOGo/dav/${config.attendee1}/Calendar/personal/` + attendee1DelegateCalendar = `/SOGo/dav/${config.attendee1_delegate}/Calendar/personal/` + + // fetch non existing event to let sogo create the calendars in the db + await _getEvent(webdav, userCalendar, 'nonexistent', 404) + await _getEvent(webdavAttendee1, attendee1Calendar, 'nonexistent', 404) + await _getEvent(webdavAttendee1Delegate, attendee1DelegateCalendar, 'nonexistent', 404) + + // list of ics used by the test. + // afterAll will loop over this and wipe them in all users' calendar + icsList = [] + }) + + afterAll(async function() { + await prefs.set('PreventInvitationsWhitelist', {}) + await prefs.set('PreventInvitations', 0) + // delete all created events from all users' calendar + for (const ics of icsList) { + await webdav_su.deleteObject(userCalendar + ics) + await webdav_su.deleteObject(attendee1Calendar + ics) + await webdav_su.deleteObject(attendee1DelegateCalendar + ics) + } + }) + + it(`Set/get the PreventInvitation pref`, async function() { + // First accept the invitation + await prefs.set('PreventInvitations', 0) + const settings = await prefs.getSettings() + const { Calendar: { PreventInvitations } = {} } = settings + expect(PreventInvitations) + .withContext(`Don't prevent invitations`) + .toBe(0) + await _addAttendee() + await _verifyEvent() + }) + + it(`Set PreventInvitation and don't accept the Invitation`, async function() { + // Second, enable PreventInviation and refuse it + await prefs.set('PreventInvitations', 1) + const settings = await prefs.getSettings() + const { Calendar: { PreventInvitations } = {} } = settings + expect(PreventInvitations) + .withContext(`Prevent invitations is enabled`) + .toBe(1) + await _addAttendee(409) + await _verifyEvent(404) + }) + + it(`Set PreventInvitation add to WhiteList and accept the Invitation`, async function() { + // First, add the Organiser to the Attendee's whitelist + await prefs.set('PreventInvitations', 1) + await prefs.set('PreventInvitationsWhitelist', config.white_listed_attendee) + const settings = await prefs.getSettings() + const { Calendar: { PreventInvitations, PreventInvitationsWhitelist } = {} } = settings + expect(PreventInvitations) + .withContext(`Prevent invitations is enabled`) + .toBe(1) + expect(PreventInvitationsWhitelist) + .withContext(`Prevent invitations is enabled, one user is whitelisted`) + .toEqual(config.white_listed_attendee) + // Second, try again to invite, it should work + await _addAttendee() + await _verifyEvent() + }) +}) \ No newline at end of file diff --git a/Tests/spec/CalDAVSchedulingSpec.js b/Tests/spec/CalDAVSchedulingSpec.js index 05830c312..1de4caabf 100644 --- a/Tests/spec/CalDAVSchedulingSpec.js +++ b/Tests/spec/CalDAVSchedulingSpec.js @@ -39,35 +39,6 @@ describe('create, read, modify, delete tasks for regular user', function() { return hrefs } - const _newDateTimeProperty = function(propertyName, dateObject = new Date()) { - let property = new ICAL.Property(propertyName) - property.setParameter('tzid', 'America/Toronto') - property.setValue(ICAL.Time.fromJSDate(dateObject)) - - return property - } - - const _newEvent = function(summary = 'test event', uid = 'test', transp = 'OPAQUE') { - const vcalendar = new ICAL.Component('vcalendar') - const vevent = new ICAL.Component('vevent') - const now = new Date() - const later = new Date(now.getTime() + 1000*60*60) - - vcalendar.addSubcomponent(vevent) - vevent.addPropertyWithValue('uid', uid) - vevent.addPropertyWithValue('summary', summary) - vevent.addPropertyWithValue('transp', transp) - vevent.addProperty(_newDateTimeProperty('dtstart', now)) - vevent.addProperty(_newDateTimeProperty('dtend', later)) - vevent.addProperty(_newDateTimeProperty('dtstamp', now)) - vevent.addProperty(_newDateTimeProperty('last-modified', now)) - vevent.addProperty(_newDateTimeProperty('created', now)) - vevent.addPropertyWithValue('class', 'PUBLIC') - vevent.addPropertyWithValue('sequence', '0') - - return vcalendar - } - const _putEvent = async function(client, calendarName, filename, event, expectedCode = 201) { const response = await client.createCalendarObject(calendarName, filename, event.toString()) expect(response.status) @@ -166,7 +137,7 @@ describe('create, read, modify, delete tasks for regular user', function() { await _deleteEvent(webdavAttendee1, attendee1Calendar + icsName) // 1. create an event in the organizer's calendar - vcalendar = _newEvent('Test add attendee', 'Test add attendee') + vcalendar = utility.createCalendar('Test add attendee', 'Test add attendee') vevent = vcalendar.getFirstSubcomponent('vevent') organizer = new ICAL.Property('organizer') organizer.setParameter('cn', user.displayname) @@ -206,7 +177,7 @@ describe('create, read, modify, delete tasks for regular user', function() { await _deleteEvent(webdavAttendee1, attendee1Calendar + icsName) // 1. create an event in the organizer's calendar - vcalendar = _newEvent('Test uninvite attendee', 'Test uninvite attendee') + vcalendar = utility.createCalendar('Test uninvite attendee', 'Test uninvite attendee') vevent = vcalendar.getFirstSubcomponent('vevent') organizer = new ICAL.Property('organizer') organizer.setParameter('cn', user.displayname) @@ -237,7 +208,7 @@ describe('create, read, modify, delete tasks for regular user', function() { // 5. uninvite the attendee - put the event back without the attendee vevent = vcalendarNoAttendee.getFirstSubcomponent('vevent') - vevent.addProperty(_newDateTimeProperty('last-modified')) + vevent.addProperty(utility.createDateTimeProperty('last-modified')) await _putEvent(webdav, userCalendar, icsName, vcalendarNoAttendee, 204) // 6. verify that the attendee doesn't have the event anymore @@ -259,7 +230,7 @@ describe('create, read, modify, delete tasks for regular user', function() { await _deleteEvent(webdav, userCalendar + obIcsName) // 1. create an event in the organizer's calendar - vcalendar = _newEvent('Test no overbook', 'Test no overbook') + vcalendar = utility.createCalendar('Test no overbook', 'Test no overbook') vevent = vcalendar.getFirstSubcomponent('vevent') organizer = new ICAL.Property('organizer') organizer.setParameter('cn', user.displayname) @@ -274,7 +245,7 @@ describe('create, read, modify, delete tasks for regular user', function() { await _putEvent(webdav, userCalendar, icsName, vcalendar) // 2. create a second event overlapping the first one - vcalendar = _newEvent('Test no overbook - overlap', 'Test no overbook - overlap') + vcalendar = utility.createCalendar('Test no overbook - overlap', 'Test no overbook - overlap') vevent = vcalendar.getFirstSubcomponent('vevent') organizer = new ICAL.Property('organizer') organizer.setParameter('cn', user.displayname) @@ -306,7 +277,7 @@ describe('create, read, modify, delete tasks for regular user', function() { await _deleteEvent(webdav, userCalendar + obIcsName) // 1. create an event in the organizer's calendar - vcalendar = _newEvent('Test can overbook', 'Test can overbook') + vcalendar = utility.createCalendar('Test can overbook', 'Test can overbook') vevent = vcalendar.getFirstSubcomponent('vevent') organizer = new ICAL.Property('organizer') organizer.setParameter('cn', user.displayname) @@ -321,7 +292,7 @@ describe('create, read, modify, delete tasks for regular user', function() { await _putEvent(webdav, userCalendar, icsName, vcalendar) // 2. create a second event overlapping the first one - vcalendar = _newEvent('Test can overbook - overlap', 'Test can overbook - overlap') + vcalendar = utility.createCalendar('Test can overbook - overlap', 'Test can overbook - overlap') vevent = vcalendar.getFirstSubcomponent('vevent') organizer = new ICAL.Property('organizer') organizer.setParameter('cn', user.displayname) @@ -373,7 +344,7 @@ describe('create, read, modify, delete tasks for regular user', function() { await _deleteEvent(webdav, userCalendar + overlapRecurringIcsName) // 1. create recurring event with resource - vcalendar = _newEvent('Recurring event with resource', 'Recurring event with resource') + vcalendar = utility.createCalendar('Recurring event with resource', 'Recurring event with resource') vevent = vcalendar.getFirstSubcomponent('vevent') rrule = new ICAL.Property('rrule') recur = new ICAL.Recur({ freq: 'DAILY', count: 5 }) @@ -396,7 +367,7 @@ describe('create, read, modify, delete tasks for regular user', function() { await _putEvent(webdav, userCalendar, icsName, vcalendar) // 2. Create single event overlaping one instance for the previous event - vcalendar = _newEvent('Recurring event with resource - overlap', 'Recurring event with resource - overlap') + vcalendar = utility.createCalendar('Recurring event with resource - overlap', 'Recurring event with resource - overlap') vevent = vcalendar.getFirstSubcomponent('vevent') organizer = new ICAL.Property('organizer') organizer.setParameter('cn', attendee1.displayname) @@ -421,8 +392,8 @@ describe('create, read, modify, delete tasks for regular user', function() { nenddate = new Date(nstartdate.getTime() + 1000*60*60) vevent.removeProperty('dtstart') vevent.removeProperty('dtend') - vevent.addProperty(_newDateTimeProperty('dtstart', nstartdate)) - vevent.addProperty(_newDateTimeProperty('dtend', nenddate)) + vevent.addProperty(utility.createDateTimeProperty('dtstart', nstartdate)) + vevent.addProperty(utility.createDateTimeProperty('dtend', nenddate)) vevent.updatePropertyWithValue('uid', 'recurring - nooverlap') await _putEvent(webdav, userCalendar, noOverlapRecurringIcsName, vcalendarNoOverlap) @@ -433,8 +404,8 @@ describe('create, read, modify, delete tasks for regular user', function() { nenddate = new Date(nstartdate.getTime() + 1000*60*60) vevent.removeProperty('dtstart') vevent.removeProperty('dtend') - vevent.addProperty(_newDateTimeProperty('dtstart', nstartdate)) - vevent.addProperty(_newDateTimeProperty('dtend', nenddate)) + vevent.addProperty(utility.createDateTimeProperty('dtstart', nstartdate)) + vevent.addProperty(utility.createDateTimeProperty('dtend', nenddate)) vevent.updatePropertyWithValue('uid', 'recurring - nooverlap') await _putEvent(webdav, userCalendar, overlapRecurringIcsName, vcalendarNoOverlap, 409) }) @@ -465,7 +436,7 @@ describe('create, read, modify, delete tasks for regular user', function() { // 1. create a recurring event in the organizer's calendar summary = 'Test reccuring exception invite cancel' uid = 'Test-recurring-exception-invite-cancel' - vcalendar = _newEvent(summary, uid) + vcalendar = utility.createCalendar(summary, uid) vevent = vcalendar.getFirstSubcomponent('vevent') rrule = new ICAL.Property('rrule') recur = new ICAL.Recur({ freq: 'DAILY', count: 5 }) @@ -480,13 +451,13 @@ describe('create, read, modify, delete tasks for regular user', function() { // 2. Add an exception to the master event and invite attendee1 to it vevent = vcalendarOrganizer.getFirstSubcomponent('vevent') vevent.removeProperty('last-modified') - vevent.addProperty(_newDateTimeProperty('last-modified')) + vevent.addProperty(utility.createDateTimeProperty('last-modified')) originalStartDate = vevent.getFirstPropertyValue('dtstart') veventException = new ICAL.Component('vevent') - veventException.addProperty(_newDateTimeProperty('created')) - veventException.addProperty(_newDateTimeProperty('last-modified')) - veventException.addProperty(_newDateTimeProperty('dtstamp')) + veventException.addProperty(utility.createDateTimeProperty('created')) + veventException.addProperty(utility.createDateTimeProperty('last-modified')) + veventException.addProperty(utility.createDateTimeProperty('dtstamp')) veventException.addPropertyWithValue('uid', uid) veventException.addPropertyWithValue('summary', summary) veventException.addPropertyWithValue('transp', 'OPAQUE') @@ -592,7 +563,7 @@ describe('create, read, modify, delete tasks for regular user', function() { // 1. create a recurring event in the organizer's calendar summary = 'Test rrule invitation deleted exdate dance' uid = 'Test-rrule-invitation-deleted-exdate-dance' - vcalendar = _newEvent(summary, uid) + vcalendar = utility.createCalendar(summary, uid) vevent = vcalendar.getFirstSubcomponent('vevent') rrule = new ICAL.Property('rrule') recur = new ICAL.Recur({ freq: 'DAILY', count: 5 }) @@ -641,7 +612,7 @@ describe('create, read, modify, delete tasks for regular user', function() { exdate = exdate.convertToZone(ICAL.Timezone.utcTimezone) vevent.addPropertyWithValue('exdate', exdate) vevent.removeProperty('last-modified') - vevent.addProperty(_newDateTimeProperty('last-modified')) + vevent.addProperty(utility.createDateTimeProperty('last-modified')) await _putEvent(webdavAttendee1, attendee1Calendar, icsName, vcalendarAttendee, 204) @@ -690,7 +661,7 @@ describe('create, read, modify, delete tasks for regular user', function() { // 1. create a recurring event in the organizer's calendar summary = 'Test organizer is attendee' uid = 'Test-organizer-is-attendee' - vcalendar = _newEvent(summary, uid) + vcalendar = utility.createCalendar(summary, uid) vevent = vcalendar.getFirstSubcomponent('vevent') organizer = new ICAL.Property('organizer') organizer.setParameter('cn', user.displayname) @@ -742,7 +713,7 @@ describe('create, read, modify, delete tasks for regular user', function() { // 1. create simple event summary = 'Test same uid' uid = 'Test-same-uid' - vcalendar = _newEvent(summary, uid) + vcalendar = utility.createCalendar(summary, uid) await _putEvent(webdav, userCalendar, icsName, vcalendar) @@ -763,7 +734,7 @@ describe('create, read, modify, delete tasks for regular user', function() { await _deleteEvent(webdavAttendee1Delegate, attendee1DelegateCalendar + icsName) // 1. org -> attendee => org: 1, attendee: 1 (pst=N-A), delegate: 0 - vcalendarInvitation = _newEvent() + vcalendarInvitation = utility.createCalendar() vcalendarInvitation.addPropertyWithValue('method', 'REQUEST') vevent = vcalendarInvitation.getFirstSubcomponent('vevent') organizer = new ICAL.Property('organizer') @@ -825,7 +796,7 @@ describe('create, read, modify, delete tasks for regular user', function() { // 4. attendee accepts // => org: 1 (updated), attendee: 1 (updated,pst=A), // delegate: 0 (cancelled, deleted) - vcalendarCancellation = _newEvent() + vcalendarCancellation = utility.createCalendar() vcalendarCancellation.addPropertyWithValue('method', 'CANCEL') attendees = vevent.getAllProperties('attendee') vevent = vcalendarCancellation.getFirstSubcomponent('vevent') @@ -862,8 +833,8 @@ describe('create, read, modify, delete tasks for regular user', function() { // => org: 1 (updated), attendee: 1 (updated), delegate: 0 vcalendarInvitation.updatePropertyWithValue('method', 'REQUEST') vevent.updatePropertyWithValue('sequence', '1') - vevent.updatePropertyWithValue('last-modified', _newDateTimeProperty('last-modified').getFirstValue()) - vevent.updatePropertyWithValue('dtstamp', _newDateTimeProperty('dtstamp').getFirstValue()) + vevent.updatePropertyWithValue('last-modified', utility.createDateTimeProperty('last-modified').getFirstValue()) + vevent.updatePropertyWithValue('dtstamp', utility.createDateTimeProperty('dtstamp').getFirstValue()) attendee = vevent.getFirstProperty('attendee') attendee.setParameter('partstat', 'NEEDS-ACTION') @@ -918,8 +889,8 @@ describe('create, read, modify, delete tasks for regular user', function() { // delegate: 1 (updated,partstat reset) vcalendarInvitation.updatePropertyWithValue('method', 'REQUEST') vevent.updatePropertyWithValue('sequence', '2') - vevent.updatePropertyWithValue('last-modified', _newDateTimeProperty('last-modified').getFirstValue()) - vevent.updatePropertyWithValue('dtstamp', _newDateTimeProperty('dtstamp').getFirstValue()) + vevent.updatePropertyWithValue('last-modified', utility.createDateTimeProperty('last-modified').getFirstValue()) + vevent.updatePropertyWithValue('dtstamp', utility.createDateTimeProperty('dtstamp').getFirstValue()) delegate.setParameter('partstat', 'NEEDS-ACTION') await _postEvent(webdav, userCalendar, vcalendarInvitation, user.email, [attendee1.email, attendee1DelegateCalendar.email]) @@ -938,8 +909,8 @@ describe('create, read, modify, delete tasks for regular user', function() { // delegate: 0 (cancelled, deleted) vcalendarInvitation.updatePropertyWithValue('method', 'CANCEL') vevent.updatePropertyWithValue('sequence', '3') - vevent.updatePropertyWithValue('last-modified', _newDateTimeProperty('last-modified').getFirstValue()) - vevent.updatePropertyWithValue('dtstamp', _newDateTimeProperty('dtstamp').getFirstValue()) + vevent.updatePropertyWithValue('last-modified', utility.createDateTimeProperty('last-modified').getFirstValue()) + vevent.updatePropertyWithValue('dtstamp', utility.createDateTimeProperty('dtstamp').getFirstValue()) await _postEvent(webdav, userCalendar, vcalendarInvitation, user.email, [attendee1.email, attendee1DelegateCalendar.email]) diff --git a/Tests/spec/HTTPPreferencesSpec.js b/Tests/spec/HTTPPreferencesSpec.js index d04bd5d1e..3ecc92030 100644 --- a/Tests/spec/HTTPPreferencesSpec.js +++ b/Tests/spec/HTTPPreferencesSpec.js @@ -3,16 +3,10 @@ import Preferences from '../lib/Preferences' const prefs = new Preferences(config.username, config.password) -beforeAll(async function() { - // because if not set in vacation will not be found later - // we must make sure they are there at the start - await prefs.setOrCreate('autoReplyText', '', ['defaults', 'Vacation']) - await prefs.setOrCreate('PreventInvitations', 0, ['settings', 'Calendar']) - await prefs.setOrCreate('PreventInvitationsWhitelist', {}, ['settings', 'Calendar']) -}) - describe('preferences', function() { + // preferencesTest + const _setTextPref = async function(prefText) { await prefs.set('autoReplyText', prefText) const prefData = await prefs.get('Vacation') @@ -22,7 +16,13 @@ describe('preferences', function() { .toEqual(prefText) } - // preferencesTest + beforeAll(async function() { + // because if not set in vacation will not be found later + // we must make sure they are there at the start + await prefs.setOrCreate('autoReplyText', '', ['defaults', 'Vacation']) + await prefs.setOrCreate('PreventInvitations', 0, ['settings', 'Calendar']) + await prefs.setOrCreate('PreventInvitationsWhitelist', {}, ['settings', 'Calendar']) + }) it('Set/get a text preference - normal characters', async function() { await _setTextPref('defaultText')