From 96aa4440513cc962241dfc7e284a4449d79e298f Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 20 Aug 2021 15:15:46 -0400 Subject: [PATCH] test: migration from Python to JavaScript --- Tests/lib/WebDAV.js | 25 +++++++++++ Tests/spec/DAVCalendarClassificationSpec.js | 50 +++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 Tests/spec/DAVCalendarClassificationSpec.js diff --git a/Tests/lib/WebDAV.js b/Tests/lib/WebDAV.js index cc13d790e..ce34beef7 100644 --- a/Tests/lib/WebDAV.js +++ b/Tests/lib/WebDAV.js @@ -264,6 +264,31 @@ class WebDAV { }) } + proppatchWebdav(resource, properties) { + const formattedProperties = Object.keys(properties).map(p => { + return { [`i:${p}`]: properties[p] } + }) + return davRequest({ + url: this.serverUrl + resource, + init: { + method: 'PROPPATCH', + headers: this.headers, + namespace: DAVNamespaceShorthandMap[DAVNamespace.DAV], + body: { + propertyupdate: { + _attributes: { + ...getDAVAttribute([DAVNamespace.DAV]), + 'xmlns:i': 'urn:inverse:params:xml:ns:inverse-dav' + }, + set: { + prop: formattedProperties + } + } + } + } + }) + } + currentUserPrivilegeSet(resource) { return propfind({ url: this.serverUrl + resource, diff --git a/Tests/spec/DAVCalendarClassificationSpec.js b/Tests/spec/DAVCalendarClassificationSpec.js new file mode 100644 index 000000000..c14dde0d3 --- /dev/null +++ b/Tests/spec/DAVCalendarClassificationSpec.js @@ -0,0 +1,50 @@ +import config from '../lib/config' +import WebDAV from '../lib/WebDAV' + +describe('default classification', function() { + const webdav = new WebDAV(config.username, config.password) + + const _setClassification = async function(component, classification = '') { + const resource = `/SOGo/dav/${config.username}/Calendar/` + const properties = { [`${component}-default-classification`]: classification } + + const results = await webdav.proppatchWebdav(resource, properties) + expect(results.length) + .withContext(`Set ${component} classification to ${classification}`) + .toBe(1) + + return results[0].status + } + + // HTTPDefaultClassificationTest + + it('expected failure when setting a classification with an invalid property', async function() { + let status + + status = await _setClassification('123456', 'PUBLIC') + expect(status) + .withContext('Setting an invalid classification property') + .toBe(403) + + status = await _setClassification('events', '') + expect(status) + .withContext('Setting an empty classification') + .toBe(403) + + status = await _setClassification('events', 'pouet') + expect(status) + .withContext('Setting an invalid classification') + .toBe(403) + }) + + it('setting a valid classification', async function() { + for (let component of ['events', 'tasks']) { + for (let classification of ['PUBLIC', 'PRIVATE', 'CONFIDENTIAL']) { + const status = await _setClassification(component, classification) + expect(status) + .withContext(`Set ${component} classification to ${classification}`) + .toBe(207) + } + } + }) +}) \ No newline at end of file