Skip to content

Commit

Permalink
Merge pull request #2 from JupiterOne/add-build-workflow
Browse files Browse the repository at this point in the history
add build workflow; simplify returned entries
  • Loading branch information
zemberdotnet authored Apr 12, 2024
2 parents 3ac0bf6 + 3db6a78 commit f53b966
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 69 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build
on:
pull_request:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out code repository source code
uses: actions/checkout@v3

- id: setup-node
name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm run test

- name: Run build
run: npm run build

# Publishing is done in a separate job to allow
# for all matrix builds to complete.
BuildRelease:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
name: Checkout Code
steps:
- name: Check out repo
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.AUTO_GITHUB_PAT_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Build and Release
uses: jupiterone/action-npm-build-release@v1
with:
npm_auth_token: ${{ secrets.NPM_AUTH_TOKEN }}
gh_token: ${{ secrets.AUTO_GITHUB_PAT_TOKEN }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ldapts",
"name": "@jupiterone/ldapts",
"version": "7.0.11",
"description": "LDAP client",
"main": "./dist/index.cjs",
Expand Down
8 changes: 6 additions & 2 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export class Client {
* @param {string[]} [options.explicitBufferAttributes] - List of attributes to explicitly return as buffers
* @param {Control|Control[]} [controls]
*/
public async search(baseDN: DN | string, options: SearchOptions = {}, controls?: Control | Control[]): Promise<SearchResponse> {
public async search(baseDN: DN | string, options: SearchOptions = {}, controls?: Control | Control[]): Promise<{ searchEntries: Entry[]; controls: Control[] | undefined }> {
if (!this.isConnected) {
await this._connect();
}
Expand Down Expand Up @@ -573,7 +573,11 @@ export class Client {
controls,
});

return this._sendSearch(searchRequest);
const result = await this._sendSearch(searchRequest);
return {
controls: result.controls,
searchEntries: result.searchEntries.map((e) => e.toObject(options.attributes ?? [], options.explicitBufferAttributes ?? [])),
};
}

/**
Expand Down
66 changes: 0 additions & 66 deletions tests/Client.tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import assert from 'assert';
import { promises as fs } from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';

import type { BerReader, BerWriter } from 'asn1';
import chai from 'chai';
Expand All @@ -21,7 +18,6 @@ import {
InvalidDNSyntaxError,
ModifyDNResponse,
NoSuchObjectError,
PagedResultsControl,
UndefinedTypeError,
} from '../src/index.js';

Expand Down Expand Up @@ -146,40 +142,6 @@ describe('Client', () => {
// This can fail since it's not the part being tested
}
});
it('should bind using EXTERNAL sasl mechanism', async () => {
try {
const client = new Client({
url: 'ldap://localhost:389',
});

const testsDirectory = fileURLToPath(new URL('.', import.meta.url));
const [ca, cert, key] = await Promise.all([
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFile(path.join(testsDirectory, './certs/server-ca.pem')),
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFile(path.join(testsDirectory, './certs/user.pem')),
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFile(path.join(testsDirectory, './certs/user-key.pem')),
]);

await client.startTLS({
ca,
cert,
key,
});
await client.bind('EXTERNAL');

try {
await client.unbind();
} catch {
// This can fail since it's not the part being tested
}
} catch (ex) {
// eslint-disable-next-line no-console
console.warn(`Ensure the local ldap service is running. See ../README.md#development`);
throw ex;
}
});
it('should bind with a custom control', async () => {
// Get list of supported controls and extensions:
// ldapsearch -H ldaps://ldap.jumpcloud.com -b "" -x -D uid=tony.stark,ou=Users,o=5be4c382c583e54de6a3ff52,dc=jumpcloud,dc=com -w MyRedSuitKeepsMeWarm -s base supportedFeatures supportedControl supportedExtension
Expand Down Expand Up @@ -817,33 +779,5 @@ describe('Client', () => {
},
]);
});
it('should throw if a PagedResultsControl is specified', async () => {
const pagedResultsControl = new PagedResultsControl({});

try {
await client.search('cn=test', {}, pagedResultsControl);
true.should.equal(false);
} catch (ex) {
if (ex instanceof Error) {
ex.message.should.equal('Should not specify PagedResultsControl');
} else {
assert.fail('Exception was not of type Error');
}
}
});
it('should throw if a PagedResultsControl is specified in the controls array', async () => {
const pagedResultsControl = new PagedResultsControl({});

try {
await client.search('cn=test', {}, [pagedResultsControl]);
true.should.equal(false);
} catch (ex) {
if (ex instanceof Error) {
ex.message.should.equal('Should not specify PagedResultsControl');
} else {
assert.fail('Exception was not of type Error');
}
}
});
});
});

0 comments on commit f53b966

Please sign in to comment.