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.

badnets.coffee 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. vows = require 'vows'
  2. assert = require 'assert'
  3. Netmask = require('../lib/netmask').Netmask
  4. shouldFailWithError = (msg) ->
  5. context =
  6. topic: ->
  7. try
  8. return new Netmask(@context.name)
  9. catch e
  10. return e
  11. 'should fail': (e) ->
  12. assert.ok isError(e), "is an Error object #{e}"
  13. "with error `#{msg}'": (e) ->
  14. assert.ok e.message?.toLowerCase().indexOf(msg.toLowerCase()) > -1, "'#{e.message}' =~ #{msg}"
  15. return context
  16. isError = (e) ->
  17. return typeof e == 'object' and Object.prototype.toString.call(e) == '[object Error]'
  18. vows.describe('IPs with bytes greater than 255')
  19. .addBatch
  20. '209.256.68.22/255.255.224.0': shouldFailWithError 'Invalid net'
  21. '209.180.68.22/256.255.224.0': shouldFailWithError 'Invalid mask'
  22. '209.500.70.33/19': shouldFailWithError 'Invalid net'
  23. '140.999.82': shouldFailWithError 'Invalid net'
  24. '899.174': shouldFailWithError 'Invalid net'
  25. '900': shouldFailWithError 'Invalid net'
  26. '209.157.300/19': shouldFailWithError 'Invalid net'
  27. '209.300.64.0.10': shouldFailWithError 'Invalid net'
  28. 'garbage': shouldFailWithError 'Invalid net'
  29. .export(module)
  30. vows.describe('Ranges that are a power-of-two big, but are not legal blocks')
  31. .addBatch
  32. '218.0.0.0/221.255.255.255': shouldFailWithError 'Invalid mask'
  33. '218.0.0.4/218.0.0.11': shouldFailWithError 'Invalid mask'
  34. .export(module)