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 1.8KB

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