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.

index.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. const saslprep = require('..');
  3. const chr = String.fromCodePoint;
  4. test('should work with liatin letters', () => {
  5. const str = 'user';
  6. expect(saslprep(str)).toEqual(str);
  7. });
  8. test('should work be case preserved', () => {
  9. const str = 'USER';
  10. expect(saslprep(str)).toEqual(str);
  11. });
  12. test('should work with high code points (> U+FFFF)', () => {
  13. const str = '\uD83D\uDE00';
  14. expect(saslprep(str, { allowUnassigned: true })).toEqual(str);
  15. });
  16. test('should remove `mapped to nothing` characters', () => {
  17. expect(saslprep('I\u00ADX')).toEqual('IX');
  18. });
  19. test('should replace `Non-ASCII space characters` with space', () => {
  20. expect(saslprep('a\u00A0b')).toEqual('a\u0020b');
  21. });
  22. test('should normalize as NFKC', () => {
  23. expect(saslprep('\u00AA')).toEqual('a');
  24. expect(saslprep('\u2168')).toEqual('IX');
  25. });
  26. test('should throws when prohibited characters', () => {
  27. // C.2.1 ASCII control characters
  28. expect(() => saslprep('a\u007Fb')).toThrow();
  29. // C.2.2 Non-ASCII control characters
  30. expect(() => saslprep('a\u06DDb')).toThrow();
  31. // C.3 Private use
  32. expect(() => saslprep('a\uE000b')).toThrow();
  33. // C.4 Non-character code points
  34. expect(() => saslprep(`a${chr(0x1fffe)}b`)).toThrow();
  35. // C.5 Surrogate codes
  36. expect(() => saslprep('a\uD800b')).toThrow();
  37. // C.6 Inappropriate for plain text
  38. expect(() => saslprep('a\uFFF9b')).toThrow();
  39. // C.7 Inappropriate for canonical representation
  40. expect(() => saslprep('a\u2FF0b')).toThrow();
  41. // C.8 Change display properties or are deprecated
  42. expect(() => saslprep('a\u200Eb')).toThrow();
  43. // C.9 Tagging characters
  44. expect(() => saslprep(`a${chr(0xe0001)}b`)).toThrow();
  45. });
  46. test('should not containt RandALCat and LCat bidi', () => {
  47. expect(() => saslprep('a\u06DD\u00AAb')).toThrow();
  48. });
  49. test('RandALCat should be first and last', () => {
  50. expect(() => saslprep('\u0627\u0031\u0628')).not.toThrow();
  51. expect(() => saslprep('\u0627\u0031')).toThrow();
  52. });
  53. test('should handle unassigned code points', () => {
  54. expect(() => saslprep('a\u0487')).toThrow();
  55. expect(() => saslprep('a\u0487', { allowUnassigned: true })).not.toThrow();
  56. });