Commit 3c8adb25 authored by Mark Stenglein's avatar Mark Stenglein Committed by GitHub
Browse files

Merge pull request #22 from ocelotsloth/3-dir-entry-ref

3 dir entry ref
parents 7322e73d dbf66867
Pipeline #1226 passed with stage
in 42 seconds
......@@ -21,20 +21,22 @@
"author": "Mark Stenglein",
"license": "AGPL-3.0",
"devDependencies": {
"@types/node": "^7.0.12",
"@types/chai": "^3.4.35",
"@types/mocha": "^2.2.39",
"@types/moment-timezone": "^0.2.34",
"@types/sinon": "^1.16.35",
"@types/sinon": "^2.1.1",
"chai": "^3.5.0",
"mocha": "^3.2.0",
"mochawesome": "^2.0.4",
"nyc": "^10.1.2",
"sinon": "^1.17.7",
"ts-node": "^2.1.0",
"tslint": "^4.4.2",
"sinon": "^2.1.0",
"ts-node": "^3.0.2",
"tslint": "^5.0.0",
"typescript": "^2.1.6"
},
"dependencies": {},
"dependencies": {
},
"nyc": {
"include": [
"src/*.ts",
......
/*
* lib-ical
* Copyright (C) 2017 Mark Stenglein
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import Parameter from "./Parameter";
import * as url from "url";
const URL = url.URL;
/**
* DelegatorsParam Class (Chapter 3.2.4)
*
* - Purpose: To specify reference to a directory entry associated with the
* calendar user specified by the property.
*
* - Format Definition: This property parameter is defined by the following
* notation:
*
* - dirparam = "DIR" "=" DQUOTE uri DQUOTE
*
* - Description:
* - Can be specified on properties with a CAL-ADDRESS value type.
* - TODO: enforce this
* - Specifies a reference to the directory entry associated with the
* calendar user specified by the property.
* - The parameter value is a URI.
* - DONE: enforce that the URI is valid
* - The URI MUST be specified in a quoted-string.
*
* - Example:
*
* ORGANIZER;DIR="ldap://example.com:6666/o=ABC%20Industries,
* c=US???(cn=Jim%20Dolittle)":mailto:jimdo@example.com
*
* @since 0.1.0
* @author Mark Stenglein <mark@stengle.in>
*/
export default class DirectoryEntryReference extends Parameter {
/** @access private */
public _uri: url.URL;
/**
* Builds a new DirectoryEntryReference object.
*
* @author Mark Stenglein <mark@stengle.in>
* @since 0.1.0
* @param uri Valid URI String (throws no error on malformed, but still valid URI)
* @access public
*/
constructor(uri: string) {
if (!uri) {
throw new TypeError("uri must be defined for DirectoryEntryReference");
}
else {
super("DIR", []);
this.uri = uri;
this.reqContentValue = true;
}
}
/**
* Returns the href form of the stored URI
*
* @author Mark Stenglein <mark@stengle.in>
* @since 0.1.0
* @returns String href of stored URI
* @access public
*/
get uri(): string {
return this._uri.href;
}
/**
* Allows you to set the URI to ANY valid URI.
*
* - This method does NOT make any assumptions over what you meant to say,
* if by happenstance your input string can be interpreted as a valid URI,
* lib-ical will not complain.
*
* @author Mark Stenglein <mark@stengle.in>
* @since 0.1.0
* @param newUri string value of the new URI which is to be validated
* @returns void
* @access public
*/
set uri(newUri: string) {
this._uri = new URL(newUri);
this.paramValues = [`"${this._uri}"`];
}
}
/*
* lib-ical
* Copyright (C) 2017 Mark Stenglein
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import DirectoryEntryReference from "../src/DirectoryEntryReference";
import { expect } from "chai";
import "mocha";
/**
* Test the DelegatorsParam class.
*/
describe("DirectoryEntryReference:", () => {
it("Should exist", () => {
expect(DirectoryEntryReference).to.exist;
});
describe("constructor:", () => {
it("should create an object", () => {
const param = new DirectoryEntryReference("ldap://valid.com:444");
expect(param).to.exist;
});
it("should complain on empty uri", () => {
expect(() => {
const param = new DirectoryEntryReference("");
}).to.throw("uri must be defined for DirectoryEntryReference");
});
});
describe("get/set methods:", () => {
describe("uri:", () => {
it("should properly set the URI and give the same return", () => {
const URI = "ldap://me@example.com:6666/0=ABC%20Industries,c=US???"
+ "(cn=Jim%20Dolittle)";
const param = new DirectoryEntryReference(URI);
param.uri = URI;
expect(param.uri).to.be.equal(URI);
});
describe("throw exception on invalid uri:", () => {
it("leading dash", () => {
expect(() => {
const URI = "-invalid://example.com:66/t/e/s/t";
const param = new DirectoryEntryReference(URI);
}).to.throw("Invalid URL");
});
it("space", () => {
expect(() => {
const URI = "in valid://example.com:66/t/e/s/t";
const param = new DirectoryEntryReference(URI);
}).to.throw("Invalid URL");
});
});
});
});
describe("generator:", () => {
it("generates properly", () => {
const URI = "ldap://example.com:6666/o=ABC%20Industries,c=US???"
+ "(cn=Jim%20Dolittle)";
const param = new DirectoryEntryReference(URI);
expect(param.generate()).to.equal(`DIR="${URI}"`);
});
it("escapes spaces and other special chars", () => {
const URI = "http://example.com/test/with/a space/inside";
const param = new DirectoryEntryReference(URI);
const expectedURI = "http://example.com/test/with/a%20space/inside";
expect(param.generate()).to.equal(`DIR="${expectedURI}"`);
});
});
});
This diff is collapsed.
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