Skip to content
Permalink
Browse files

Add entity cap generation tests

  • Loading branch information
legastero committed Dec 20, 2019
1 parent 0039b0e commit 88928c595e89f509a6aa49fda3fbb966b760d7ec
Showing with 67,033 additions and 26 deletions.
  1. +13 −0 NOTICE.md
  2. +31 −25 src/helpers/LegacyEntityCapabilities.ts
  3. +1 −1 test/disco/disco-manager.ts
  4. +66,736 −0 test/disco/legacy-caps-db.json
  5. +252 −0 test/disco/legacy-entity-capabilities.ts
@@ -339,3 +339,16 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

## capsdb

capsdb - A collection of XMPP caps with hashes

Written in 2015 by Thijs Alkemade me@thijsalkema.de

To the extent possible under law, the author(s) have dedicated all copyright and
related and neighboring rights to this software to the public domain worldwide.
This software is distributed without any warranty.

You should have received a copy of the CC0 Public Domain Dedication along with
this software. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
@@ -48,15 +48,17 @@ function encodeForms(extensions: DataForm[] = []): Buffer[] | null {
let type: Buffer | undefined;

for (const field of form.fields || []) {
if (
field.name === 'FORM_TYPE' &&
field.type === 'hidden' &&
field.rawValues &&
field.rawValues.length === 1
) {
if (!(field.name === 'FORM_TYPE' && field.type === 'hidden')) {
continue;
}
if (field.rawValues && field.rawValues.length === 1) {
type = escape(field.rawValues[0]);
break;
}
if (field.value && typeof field.value === 'string') {
type = escape(field.value);
break;
}
}

if (!type) {
@@ -94,10 +96,27 @@ function encodeFields(fields: DataFormField[] = []): Buffer[] {
if (field.name === 'FORM_TYPE') {
continue;
}
sortedFields.push({
name: escape(field.name!),
values: (field.rawValues || []).map(val => escape(val)).sort(octetCompare)
});
if (field.rawValues) {
sortedFields.push({
name: escape(field.name!),
values: field.rawValues.map(val => escape(val)).sort(octetCompare)
});
} else if (Array.isArray(field.value)) {
sortedFields.push({
name: escape(field.name!),
values: field.value.map(val => escape(val)).sort(octetCompare)
});
} else if (field.value === true || field.value === false) {
sortedFields.push({
name: escape(field.name!),
values: [escape(field.value ? '1' : '0')]
});
} else {
sortedFields.push({
name: escape(field.name!),
values: [escape(field.value || '')]
});
}
}

sortedFields.sort((a, b) => octetCompare(a.name, b.name));
@@ -118,12 +137,9 @@ export function generate(info: DiscoInfo, hashName: string): string | null {
const S: Buffer[] = [];
const separator = Buffer.from('<', 'utf8');

const append = (b1: Buffer, b2?: Buffer) => {
const append = (b1: Buffer) => {
S.push(b1);
S.push(separator);
if (b2) {
S.push(b2);
}
};

const identities = encodeIdentities(info.identities);
@@ -144,19 +160,9 @@ export function generate(info: DiscoInfo, hashName: string): string | null {
append(form);
}

let version = Hashes.createHash(hashName)
return Hashes.createHash(hashName)
.update(Buffer.concat(S))
.digest('base64');

let padding = 4 - (version.length % 4);
if (padding === 4) {
padding = 0;
}
for (let i = 0; i < padding; i++) {
version += '=';
}

return version;
}

export function verify(info: DiscoInfo, hashName: string, check: string): boolean {
@@ -1,5 +1,5 @@
import DiscoManager from '../../src/DiscoManager';
import { DataForm, DiscoItem, DiscoInfoIdentity } from '../../src/protocol';
import { DataForm, DiscoInfoIdentity } from '../../src/protocol';

test('Disco - add identity', () => {
const disco = new DiscoManager();

0 comments on commit 88928c5

Please sign in to comment.
You can’t perform that action at this time.