// iCloud connect: when the account does not report its calendar home at the principal, the home beside it (//calendars/) is tried. const http = require('http'), fs = require('fs'), os = require('os'), path = require('path'); process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'cd-')); process.env.CALDAV_TEST = '1'; const root = path.join(__dirname, '..'); const srv = http.createServer((rq, rs) => { const p = new URL(rq.url, 'http://x').pathname, x = b => { rs.writeHead(207, { 'content-type': 'application/xml' }); rs.end('' + b + ''); }; if (p === '/') return x('//9/principal/HTTP/1.1 200 OK'); if (p === '/9/principal/') return x('/9/principal/HTTP/1.1 404 Not Found'); if (p === '/9/calendars/') return x('/9/calendars/home/HomeHTTP/1.1 200 OK'); rs.writeHead(404); rs.end(); }).listen(0, async () => { process.env.CALDAV_BASE = 'http://127.0.0.1:' + srv.address().port; const users = require(root + '/users'), caldav = require(root + '/caldav'), me = users.create({ name: 'A', role: 'admin', handle: 'YQ' }); await users.runAs(me, async () => { try { const s = await caldav.connect('a@icloud.com', 'abcd-efgh'); require('assert').deepEqual(s.calendars.map(c => c.name), ['Home']); console.log('caldav fallback ok'); } catch (e) { console.error(e); process.exitCode = 1; } }); srv.close(); process.exit(process.exitCode || 0); });