Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

fix: client.add not adding buffers properly #754

Merged
merged 4 commits into from
Aug 3, 2021

Conversation

JohnTJohnston
Copy link

Fixed while getting AD thumbnailPhoto to work.

To repro, add a thumbnailPhoto to AD.

Note: I don't believe I ever reported this problem, but I've been using the fix for a long time.

Fixed while getting AD thumbnailPhoto to work.
Copy link
Member

@UziTech UziTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test?

@JohnTJohnston
Copy link
Author

Sorry, I must have missed something in your documentation. I don't know what is assumed by your test runs. I need to be able to add a thumbnail photo to AD. Do you run your tests against AD? Can I count on the existence of a particular user?

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To repro, add a thumbnailPhoto to AD.

Sorry. This is not an effective means of proving the change. First, not everyone has access to an Active Directory instance. Second, it does not prevent regressions in future releases. A unit test is required to satisfy these requirements.

lib/client/client.js Outdated Show resolved Hide resolved
@JohnTJohnston
Copy link
Author

Sorry, I'm not clear what is expected of your unit tests. How are they supposed to work without a back end directory to verify functionality? Not sure what other attributes require passing a buffer into add, so how to test?

Seems like I may have to live with my private patches...

@jsumners
Copy link
Member

Sorry, I'm not clear what is expected of your unit tests. How are they supposed to work without a back end directory to verify functionality? Not sure what other attributes require passing a buffer into add, so how to test?

Seems like I may have to live with my private patches...

The client unit tests are in https://github.com/ldapjs/node-ldapjs/blob/91de94d1a625b66b753091697632cbc6f433913d/test/client.test.js

We further have "integration" tests at https://github.com/ldapjs/node-ldapjs/tree/91de94d1a625b66b753091697632cbc6f433913d/test-integration/client

The integration tests use an standard OpenLDAP instance as built by https://github.com/ldapjs/docker-test-openldap and provided via https://github.com/ldapjs/docker-test-openldap/pkgs/container/docker-test-openldap/openldap

The integration tests are useful in cases where writing a unit test is either too difficult or not sufficient.

Note: I need to do some work to update the Docker repository to GitHub's latest, truly anonymous, access mechanisms. But it is attainable currently through authenticated means.

@JohnTJohnston
Copy link
Author

I am not familiar with openldap attributes. this bug fix is specfic to attributes that require a javascript buffer to be passed in, and for all I know, openldap might have been smart enough not to have such attributes.

@jsumners
Copy link
Member

I am not familiar with openldap attributes. this bug fix is specfic to attributes that require a javascript buffer to be passed in, and for all I know, openldap might have been smart enough not to have such attributes.

We really can't merge patches without a test to cover their functionality. This PR addresses reading of binary attributes, yes? My initial theory would be that updating the server embedded in the unit tests to return an entry that has a Buffer valued attribute would allow for a unit test to be written to cover this change.

@JohnTJohnston
Copy link
Author

This was necessary to modify a binary attribute. This following test passes, but it passes both before and after the fix.

tap.test('add success with buffer', function (t) {
  const entry = {
    someAttribute: Buffer.alloc(20)
  }
  t.context.client.add('cn=add, ' + SUFFIX, entry, function (err, res) {
    t.error(err)
    t.ok(res)
    t.equal(res.status, 0)
    t.end()
  })
})

@jsumners
Copy link
Member

This following test passes, but it passes both before and after the fix.

Then we should investigate why.

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! This is what we need to help improve this library. The test fails before the patch and succeeds after.

@UziTech UziTech merged commit b971204 into ldapjs:master Aug 3, 2021
@jsumners
Copy link
Member

⚠️ This issue has been locked due to age. If you have encountered a recent
problem that seems to be covered by this issue, please open a new issue.

Please include a minimal reproducible example
when opening a new issue.

@ldapjs ldapjs locked as resolved and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants