Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ldap-escape.test.js 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. 'use strict';
  2. var ldapEscape = require('../index');
  3. describe('ldap-escape', function () {
  4. describe('.filter', function () {
  5. it('should work in the base case (no escaping), returning a string', function () {
  6. const uid = 1337;
  7. expect(ldapEscape.filter`(uid=${uid})`).toBe('(uid=1337)');
  8. });
  9. it('should correctly escape the OWASP Christmas Tree Example', function () {
  10. const test = 'Hi (This) = is * a \\ test # ç à ô';
  11. expect(ldapEscape.filter`(test=${test})`).toBe('(test=Hi \\28This\\29 = is \\2a a \\5c test # ç à ô)');
  12. });
  13. it('should correctly escape the PHP test case', function () {
  14. const test = 'foo=bar(baz)*';
  15. expect(ldapEscape.filter`${test}`).toBe('foo=bar\\28baz\\29\\2a');
  16. });
  17. });
  18. describe('.dn', function () {
  19. it('should work in the base case (no escaping), returning a string', function () {
  20. const cn = 'alice';
  21. const dc = 'com';
  22. expect(ldapEscape.dn`cn=${cn},dc=${dc}`).toBe('cn=alice,dc=com');
  23. });
  24. it('should escape a leading space', function () {
  25. const cn = ' alice';
  26. const dc = 'com';
  27. expect(ldapEscape.dn`cn=${cn},dc=${dc}`).toBe('cn=\\ alice,dc=com');
  28. });
  29. it('should escape a leading hash', function () {
  30. const cn = '#alice';
  31. const dc = 'com';
  32. expect(ldapEscape.dn`cn=${cn},dc=${dc}`).toBe('cn=\\#alice,dc=com');
  33. });
  34. it('should escape a leading hash and trailing space', function () {
  35. const cn = '# ';
  36. const dc = 'com';
  37. expect(ldapEscape.dn`cn=${cn},dc=${dc}`).toBe('cn=\\#\\ ,dc=com');
  38. });
  39. it('should escape a trailing space', function () {
  40. const cn = 'alice ';
  41. const dc = 'com';
  42. expect(ldapEscape.dn`cn=${cn},dc=${dc}`).toBe('cn=alice\\ ,dc=com');
  43. });
  44. it('should escape a dn of just 3 spaces', function () {
  45. const cn = ' ';
  46. const dc = 'com';
  47. expect(ldapEscape.dn`cn=${cn},dc=${dc}`).toBe('cn=\\ \\ ,dc=com');
  48. });
  49. it('should correctly escape the OWASP Christmas Tree Example', function () {
  50. const dn = ' Hello\\ + , "World" ; ';
  51. expect(ldapEscape.dn`${dn}`).toBe('\\ Hello\\\\ \\+ \\, \\\"World\\\" \\;\\ ');
  52. });
  53. it('should correctly escape the Active Directory Examples', function () {
  54. let cn, ou;
  55. cn = 'Smith, James K.';
  56. expect(ldapEscape.dn`cn=${cn},ou=West,dc=MyDomain,dc=com`).toBe('cn=Smith\\, James K.,ou=West,dc=MyDomain,dc=com');
  57. ou = 'Sales\\Engineering';
  58. expect(ldapEscape.dn`ou=${ou},dc=MyDomain,dc=com`).toBe('ou=Sales\\\\Engineering,dc=MyDomain,dc=com');
  59. cn = 'East#Test + Lab';
  60. expect(ldapEscape.dn`cn=${cn},ou=West,dc=MyDomain,dc=com`).toBe('cn=East\\#Test \\+ Lab,ou=West,dc=MyDomain,dc=com');
  61. cn = ' Jim Smith ';
  62. expect(ldapEscape.dn`cn=${cn},ou=West,dc=MyDomain,dc=com`).toBe('cn=\\ Jim Smith\\ ,ou=West,dc=MyDomain,dc=com');
  63. });
  64. });
  65. });