search-result-done.test.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict'
  2. const tap = require('tap')
  3. const { BerReader } = require('@ldapjs/asn1')
  4. const { operations } = require('@ldapjs/protocol')
  5. const {
  6. searchResultDoneBytes
  7. } = require('./_fixtures/message-byte-arrays')
  8. const SearchResultDone = require('./search-result-done')
  9. tap.test('basic', async t => {
  10. const res = new SearchResultDone()
  11. t.equal(res.protocolOp, operations.LDAP_RES_SEARCH_DONE)
  12. t.equal(res.type, 'SearchResultDone')
  13. })
  14. tap.test('toBer', t => {
  15. tap.test('returns basic bytes', async t => {
  16. const res = new SearchResultDone({ messageId: 2 })
  17. const ber = res.toBer()
  18. const expected = Buffer.from(searchResultDoneBytes)
  19. t.equal(expected.compare(ber.buffer), 0)
  20. })
  21. t.end()
  22. })
  23. tap.test('#parseToPojo', t => {
  24. t.test('parses a basic object', async t => {
  25. const bytes = searchResultDoneBytes.slice(5)
  26. const reader = new BerReader(Buffer.from(bytes))
  27. const pojo = SearchResultDone.parseToPojo(reader)
  28. t.strictSame(pojo, {
  29. status: 0,
  30. matchedDN: '',
  31. diagnosticMessage: '',
  32. referrals: []
  33. })
  34. })
  35. t.test('throws if protocol op is wrong', async t => {
  36. const bytes = searchResultDoneBytes.slice(5)
  37. bytes[0] = 0x68
  38. const reader = new BerReader(Buffer.from(bytes))
  39. t.throws(
  40. () => SearchResultDone.parseToPojo(reader),
  41. Error('found wrong protocol operation: 0x68')
  42. )
  43. })
  44. t.end()
  45. })