PageRenderTime 50ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/test/shoulda_macros/models.rb

https://github.com/newrooky/lftwb
Ruby | 34 lines | 32 code | 2 blank | 0 comment | 0 complexity | 0ee28aead7d57bd1dd0aa9ff4e68e904 MD5 | raw file
Possible License(s): MIT
  1. Test::Unit::TestCase.class_eval do
  2. def self.should_whitelist(*attributes)
  3. bad_scripts = [
  4. %|';alert(String.fromCharCode(88,83,83))//\';alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>|,
  5. %|'';!--"<XSS>=&{()}|,
  6. %|<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>|,
  7. %|<IMG SRC="javascript:alert('XSS');">|,
  8. %|<IMG SRC=javascript:alert('XSS')>|,
  9. %|<IMG SRC=JaVaScRiPt:alert('XSS')>|,
  10. %|<IMG SRC=JaVaScRiPt:alert('XSS')>|,
  11. %|<IMG SRC=`javascript:alert("RSnake says, 'XSS'")`>|,
  12. %|<IMG """><SCRIPT>alert("XSS")</SCRIPT>">|,
  13. %|<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>|,
  14. %|<A HREF="h
  15. tt p://6&#9;6.000146.0x7.147/">XSS</A>|,
  16. %|<script>alert('message');</script>| ]
  17. klass = model_class
  18. attributes.each do |attribute|
  19. attribute = attribute.to_sym
  20. should "white list #{attribute}" do
  21. assert object = klass.find(:first), "Can't find first #{klass}"
  22. bad_scripts.each do |bad_value|
  23. object.send("#{attribute}=", bad_value)
  24. object.save
  25. clean_value = object.send("#{attribute}")
  26. assert !clean_value.include?(bad_value), "#{attribute} is not white listed. #{bad_value} made it through"
  27. end
  28. end
  29. end
  30. end
  31. end