metasploit-model 0.24.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (380) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +27 -0
  4. data/.rspec +4 -0
  5. data/.simplecov +38 -0
  6. data/.travis.yml +6 -0
  7. data/.yardopts +5 -0
  8. data/Gemfile +43 -0
  9. data/LICENSE +27 -0
  10. data/README.md +33 -0
  11. data/Rakefile +52 -0
  12. data/app/models/metasploit/model/association/reflection.rb +46 -0
  13. data/app/models/metasploit/model/module/ancestor/spec/template.rb +125 -0
  14. data/app/models/metasploit/model/module/class/spec/template.rb +92 -0
  15. data/app/models/metasploit/model/module/instance/spec/template.rb +97 -0
  16. data/app/models/metasploit/model/search/group/base.rb +21 -0
  17. data/app/models/metasploit/model/search/group/intersection.rb +4 -0
  18. data/app/models/metasploit/model/search/group/union.rb +4 -0
  19. data/app/models/metasploit/model/search/operation/base.rb +39 -0
  20. data/app/models/metasploit/model/search/operation/boolean.rb +36 -0
  21. data/app/models/metasploit/model/search/operation/date.rb +37 -0
  22. data/app/models/metasploit/model/search/operation/integer.rb +14 -0
  23. data/app/models/metasploit/model/search/operation/null.rb +26 -0
  24. data/app/models/metasploit/model/search/operation/set.rb +34 -0
  25. data/app/models/metasploit/model/search/operation/set/integer.rb +5 -0
  26. data/app/models/metasploit/model/search/operation/set/string.rb +5 -0
  27. data/app/models/metasploit/model/search/operation/string.rb +11 -0
  28. data/app/models/metasploit/model/search/operation/union.rb +59 -0
  29. data/app/models/metasploit/model/search/operator/association.rb +43 -0
  30. data/app/models/metasploit/model/search/operator/attribute.rb +60 -0
  31. data/app/models/metasploit/model/search/operator/base.rb +34 -0
  32. data/app/models/metasploit/model/search/operator/delegation.rb +40 -0
  33. data/app/models/metasploit/model/search/operator/deprecated/app.rb +27 -0
  34. data/app/models/metasploit/model/search/operator/deprecated/author.rb +33 -0
  35. data/app/models/metasploit/model/search/operator/deprecated/authority.rb +43 -0
  36. data/app/models/metasploit/model/search/operator/deprecated/platform.rb +45 -0
  37. data/app/models/metasploit/model/search/operator/deprecated/ref.rb +50 -0
  38. data/app/models/metasploit/model/search/operator/deprecated/text.rb +32 -0
  39. data/app/models/metasploit/model/search/operator/null.rb +44 -0
  40. data/app/models/metasploit/model/search/operator/single.rb +98 -0
  41. data/app/models/metasploit/model/search/operator/union.rb +33 -0
  42. data/app/models/metasploit/model/search/query.rb +171 -0
  43. data/app/models/metasploit/model/spec/template.rb +273 -0
  44. data/app/models/metasploit/model/visitation/visitor.rb +69 -0
  45. data/app/validators/derivation_validator.rb +17 -0
  46. data/app/validators/dynamic_length_validator.rb +45 -0
  47. data/app/validators/ip_format_validator.rb +31 -0
  48. data/app/validators/nil_validator.rb +16 -0
  49. data/app/validators/parameters_validator.rb +147 -0
  50. data/app/validators/password_is_strong_validator.rb +115 -0
  51. data/config/locales/en.yml +209 -0
  52. data/lib/metasploit/model.rb +38 -0
  53. data/lib/metasploit/model/architecture.rb +346 -0
  54. data/lib/metasploit/model/association.rb +49 -0
  55. data/lib/metasploit/model/association/error.rb +40 -0
  56. data/lib/metasploit/model/author.rb +58 -0
  57. data/lib/metasploit/model/authority.rb +134 -0
  58. data/lib/metasploit/model/authority/bid.rb +10 -0
  59. data/lib/metasploit/model/authority/cve.rb +10 -0
  60. data/lib/metasploit/model/authority/msb.rb +10 -0
  61. data/lib/metasploit/model/authority/osvdb.rb +10 -0
  62. data/lib/metasploit/model/authority/pmasa.rb +10 -0
  63. data/lib/metasploit/model/authority/secunia.rb +10 -0
  64. data/lib/metasploit/model/authority/us_cert_vu.rb +10 -0
  65. data/lib/metasploit/model/authority/waraxe.rb +31 -0
  66. data/lib/metasploit/model/authority/zdi.rb +10 -0
  67. data/lib/metasploit/model/base.rb +25 -0
  68. data/lib/metasploit/model/configuration.rb +72 -0
  69. data/lib/metasploit/model/configuration/autoload.rb +109 -0
  70. data/lib/metasploit/model/configuration/child.rb +12 -0
  71. data/lib/metasploit/model/configuration/error.rb +4 -0
  72. data/lib/metasploit/model/configuration/i18n.rb +54 -0
  73. data/lib/metasploit/model/configuration/parent.rb +50 -0
  74. data/lib/metasploit/model/configured.rb +46 -0
  75. data/lib/metasploit/model/derivation.rb +110 -0
  76. data/lib/metasploit/model/derivation/full_name.rb +25 -0
  77. data/lib/metasploit/model/email_address.rb +128 -0
  78. data/lib/metasploit/model/engine.rb +34 -0
  79. data/lib/metasploit/model/error.rb +7 -0
  80. data/lib/metasploit/model/file.rb +49 -0
  81. data/lib/metasploit/model/invalid.rb +17 -0
  82. data/lib/metasploit/model/module.rb +8 -0
  83. data/lib/metasploit/model/module/action.rb +58 -0
  84. data/lib/metasploit/model/module/ancestor.rb +494 -0
  85. data/lib/metasploit/model/module/architecture.rb +40 -0
  86. data/lib/metasploit/model/module/author.rb +47 -0
  87. data/lib/metasploit/model/module/class.rb +406 -0
  88. data/lib/metasploit/model/module/handler.rb +35 -0
  89. data/lib/metasploit/model/module/instance.rb +626 -0
  90. data/lib/metasploit/model/module/path.rb +165 -0
  91. data/lib/metasploit/model/module/platform.rb +38 -0
  92. data/lib/metasploit/model/module/rank.rb +91 -0
  93. data/lib/metasploit/model/module/reference.rb +38 -0
  94. data/lib/metasploit/model/module/stance.rb +22 -0
  95. data/lib/metasploit/model/module/target.rb +80 -0
  96. data/lib/metasploit/model/module/target/architecture.rb +42 -0
  97. data/lib/metasploit/model/module/target/platform.rb +42 -0
  98. data/lib/metasploit/model/module/type.rb +44 -0
  99. data/lib/metasploit/model/nilify_blanks.rb +53 -0
  100. data/lib/metasploit/model/platform.rb +250 -0
  101. data/lib/metasploit/model/real_pathname.rb +18 -0
  102. data/lib/metasploit/model/reference.rb +108 -0
  103. data/lib/metasploit/model/search.rb +63 -0
  104. data/lib/metasploit/model/search/association.rb +32 -0
  105. data/lib/metasploit/model/search/attribute.rb +51 -0
  106. data/lib/metasploit/model/search/operation.rb +31 -0
  107. data/lib/metasploit/model/search/operation/integer/value.rb +33 -0
  108. data/lib/metasploit/model/search/operation/string/value.rb +14 -0
  109. data/lib/metasploit/model/search/operator.rb +10 -0
  110. data/lib/metasploit/model/search/operator/help.rb +47 -0
  111. data/lib/metasploit/model/search/with.rb +40 -0
  112. data/lib/metasploit/model/spec.rb +140 -0
  113. data/lib/metasploit/model/spec/error.rb +9 -0
  114. data/lib/metasploit/model/spec/i18n_exception_handler.rb +19 -0
  115. data/lib/metasploit/model/spec/pathname_collision.rb +28 -0
  116. data/lib/metasploit/model/spec/template/write.rb +42 -0
  117. data/lib/metasploit/model/spec/temporary_pathname.rb +59 -0
  118. data/lib/metasploit/model/translation.rb +31 -0
  119. data/lib/metasploit/model/version.rb +31 -0
  120. data/lib/metasploit/model/visitation.rb +9 -0
  121. data/lib/metasploit/model/visitation/visit.rb +103 -0
  122. data/lib/tasks/yard.rake +30 -0
  123. data/metasploit-model.gemspec +39 -0
  124. data/script/rails +9 -0
  125. data/spec/app/models/metasploit/model/association/reflection_spec.rb +48 -0
  126. data/spec/app/models/metasploit/model/module/ancestor/spec/template_spec.rb +174 -0
  127. data/spec/app/models/metasploit/model/module/class/spec/template_spec.rb +222 -0
  128. data/spec/app/models/metasploit/model/module/instance/spec/template_spec.rb +201 -0
  129. data/spec/app/models/metasploit/model/search/group/base_spec.rb +5 -0
  130. data/spec/app/models/metasploit/model/search/group/intersection_spec.rb +5 -0
  131. data/spec/app/models/metasploit/model/search/group/union_spec.rb +5 -0
  132. data/spec/app/models/metasploit/model/search/operation/base_spec.rb +70 -0
  133. data/spec/app/models/metasploit/model/search/operation/boolean_spec.rb +56 -0
  134. data/spec/app/models/metasploit/model/search/operation/date_spec.rb +89 -0
  135. data/spec/app/models/metasploit/model/search/operation/integer_spec.rb +9 -0
  136. data/spec/app/models/metasploit/model/search/operation/null_spec.rb +64 -0
  137. data/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb +7 -0
  138. data/spec/app/models/metasploit/model/search/operation/set/string_spec.rb +7 -0
  139. data/spec/app/models/metasploit/model/search/operation/set_spec.rb +126 -0
  140. data/spec/app/models/metasploit/model/search/operation/string_spec.rb +9 -0
  141. data/spec/app/models/metasploit/model/search/operation/union_spec.rb +124 -0
  142. data/spec/app/models/metasploit/model/search/operator/association_spec.rb +108 -0
  143. data/spec/app/models/metasploit/model/search/operator/attribute_spec.rb +104 -0
  144. data/spec/app/models/metasploit/model/search/operator/base_spec.rb +34 -0
  145. data/spec/app/models/metasploit/model/search/operator/delegation_spec.rb +108 -0
  146. data/spec/app/models/metasploit/model/search/operator/deprecated/app_spec.rb +62 -0
  147. data/spec/app/models/metasploit/model/search/operator/deprecated/author_spec.rb +161 -0
  148. data/spec/app/models/metasploit/model/search/operator/deprecated/authority_spec.rb +123 -0
  149. data/spec/app/models/metasploit/model/search/operator/deprecated/platform_spec.rb +112 -0
  150. data/spec/app/models/metasploit/model/search/operator/deprecated/ref_spec.rb +327 -0
  151. data/spec/app/models/metasploit/model/search/operator/deprecated/text_spec.rb +357 -0
  152. data/spec/app/models/metasploit/model/search/operator/null_spec.rb +41 -0
  153. data/spec/app/models/metasploit/model/search/operator/single_spec.rb +327 -0
  154. data/spec/app/models/metasploit/model/search/operator/union_spec.rb +92 -0
  155. data/spec/app/models/metasploit/model/search/query_spec.rb +742 -0
  156. data/spec/app/models/metasploit/model/spec/template_spec.rb +23 -0
  157. data/spec/app/models/metasploit/model/visitation/visitor_spec.rb +45 -0
  158. data/spec/app/validators/derivation_validator_spec.rb +92 -0
  159. data/spec/app/validators/dynamic_length_validator_spec.rb +293 -0
  160. data/spec/app/validators/ip_format_validator_spec.rb +124 -0
  161. data/spec/app/validators/nil_validator_spec.rb +69 -0
  162. data/spec/app/validators/parameters_validator_spec.rb +342 -0
  163. data/spec/app/validators/password_is_strong_validator_spec.rb +250 -0
  164. data/spec/dummy/Rakefile +7 -0
  165. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  166. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  167. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  168. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  169. data/spec/dummy/app/mailers/.gitkeep +0 -0
  170. data/spec/dummy/app/models/dummy/architecture.rb +92 -0
  171. data/spec/dummy/app/models/dummy/author.rb +15 -0
  172. data/spec/dummy/app/models/dummy/authority.rb +130 -0
  173. data/spec/dummy/app/models/dummy/email_address.rb +27 -0
  174. data/spec/dummy/app/models/dummy/module/action.rb +25 -0
  175. data/spec/dummy/app/models/dummy/module/ancestor.rb +67 -0
  176. data/spec/dummy/app/models/dummy/module/architecture.rb +19 -0
  177. data/spec/dummy/app/models/dummy/module/author.rb +28 -0
  178. data/spec/dummy/app/models/dummy/module/class.rb +69 -0
  179. data/spec/dummy/app/models/dummy/module/instance.rb +209 -0
  180. data/spec/dummy/app/models/dummy/module/path.rb +64 -0
  181. data/spec/dummy/app/models/dummy/module/platform.rb +19 -0
  182. data/spec/dummy/app/models/dummy/module/rank.rb +44 -0
  183. data/spec/dummy/app/models/dummy/module/reference.rb +19 -0
  184. data/spec/dummy/app/models/dummy/module/target.rb +62 -0
  185. data/spec/dummy/app/models/dummy/module/target/architecture.rb +19 -0
  186. data/spec/dummy/app/models/dummy/module/target/platform.rb +19 -0
  187. data/spec/dummy/app/models/dummy/platform.rb +58 -0
  188. data/spec/dummy/app/models/dummy/reference.rb +31 -0
  189. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  190. data/spec/dummy/config.ru +4 -0
  191. data/spec/dummy/config/application.rb +43 -0
  192. data/spec/dummy/config/boot.rb +10 -0
  193. data/spec/dummy/config/environment.rb +5 -0
  194. data/spec/dummy/config/environments/development.rb +27 -0
  195. data/spec/dummy/config/environments/production.rb +63 -0
  196. data/spec/dummy/config/environments/test.rb +29 -0
  197. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  198. data/spec/dummy/config/initializers/inflections.rb +15 -0
  199. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  200. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  201. data/spec/dummy/config/initializers/session_store.rb +3 -0
  202. data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
  203. data/spec/dummy/config/locales/en.yml +1 -0
  204. data/spec/dummy/config/routes.rb +2 -0
  205. data/spec/dummy/db/schema.rb +707 -0
  206. data/spec/dummy/lib/assets/.gitkeep +0 -0
  207. data/spec/dummy/log/.gitkeep +0 -0
  208. data/spec/dummy/public/404.html +26 -0
  209. data/spec/dummy/public/422.html +26 -0
  210. data/spec/dummy/public/500.html +25 -0
  211. data/spec/dummy/public/favicon.ico +0 -0
  212. data/spec/dummy/script/rails +6 -0
  213. data/spec/dummy/spec/factories/dummy/architectures.rb +13 -0
  214. data/spec/dummy/spec/factories/dummy/authorities.rb +32 -0
  215. data/spec/dummy/spec/factories/dummy/authors.rb +8 -0
  216. data/spec/dummy/spec/factories/dummy/email_addresses.rb +8 -0
  217. data/spec/dummy/spec/factories/dummy/module/actions.rb +13 -0
  218. data/spec/dummy/spec/factories/dummy/module/ancestors.rb +45 -0
  219. data/spec/dummy/spec/factories/dummy/module/architectures.rb +35 -0
  220. data/spec/dummy/spec/factories/dummy/module/authors.rb +10 -0
  221. data/spec/dummy/spec/factories/dummy/module/classes.rb +40 -0
  222. data/spec/dummy/spec/factories/dummy/module/instances.rb +86 -0
  223. data/spec/dummy/spec/factories/dummy/module/paths.rb +16 -0
  224. data/spec/dummy/spec/factories/dummy/module/platforms.rb +35 -0
  225. data/spec/dummy/spec/factories/dummy/module/ranks.rb +14 -0
  226. data/spec/dummy/spec/factories/dummy/module/references.rb +17 -0
  227. data/spec/dummy/spec/factories/dummy/module/target/architectures.rb +40 -0
  228. data/spec/dummy/spec/factories/dummy/module/target/platforms.rb +41 -0
  229. data/spec/dummy/spec/factories/dummy/module/targets.rb +46 -0
  230. data/spec/dummy/spec/factories/dummy/platforms.rb +3 -0
  231. data/spec/dummy/spec/factories/dummy/references.rb +26 -0
  232. data/spec/factories/metasploit/model/architectures.rb +6 -0
  233. data/spec/factories/metasploit/model/association/reflections.rb +9 -0
  234. data/spec/factories/metasploit/model/authorities.rb +28 -0
  235. data/spec/factories/metasploit/model/authors.rb +9 -0
  236. data/spec/factories/metasploit/model/bases.rb +10 -0
  237. data/spec/factories/metasploit/model/email_addresses.rb +14 -0
  238. data/spec/factories/metasploit/model/module/actions.rb +9 -0
  239. data/spec/factories/metasploit/model/module/ancestors.rb +180 -0
  240. data/spec/factories/metasploit/model/module/architectures.rb +15 -0
  241. data/spec/factories/metasploit/model/module/classes.rb +47 -0
  242. data/spec/factories/metasploit/model/module/handlers.rb +3 -0
  243. data/spec/factories/metasploit/model/module/instances.rb +83 -0
  244. data/spec/factories/metasploit/model/module/paths.rb +51 -0
  245. data/spec/factories/metasploit/model/module/platforms.rb +15 -0
  246. data/spec/factories/metasploit/model/module/ranks.rb +9 -0
  247. data/spec/factories/metasploit/model/module/references.rb +11 -0
  248. data/spec/factories/metasploit/model/module/stances.rb +3 -0
  249. data/spec/factories/metasploit/model/module/targets.rb +22 -0
  250. data/spec/factories/metasploit/model/module/types.rb +5 -0
  251. data/spec/factories/metasploit/model/references.rb +88 -0
  252. data/spec/factories/metasploit/model/search/operator/associations.rb +5 -0
  253. data/spec/factories/metasploit/model/search/operator/attributes.rb +7 -0
  254. data/spec/factories/metasploit/model/search/operator/bases.rb +5 -0
  255. data/spec/lib/metasploit/model/architecture_spec.rb +52 -0
  256. data/spec/lib/metasploit/model/association/error_spec.rb +48 -0
  257. data/spec/lib/metasploit/model/association_spec.rb +145 -0
  258. data/spec/lib/metasploit/model/author_spec.rb +6 -0
  259. data/spec/lib/metasploit/model/authority/bid_spec.rb +17 -0
  260. data/spec/lib/metasploit/model/authority/cve_spec.rb +17 -0
  261. data/spec/lib/metasploit/model/authority/msb_spec.rb +17 -0
  262. data/spec/lib/metasploit/model/authority/osvdb_spec.rb +17 -0
  263. data/spec/lib/metasploit/model/authority/pmasa_spec.rb +17 -0
  264. data/spec/lib/metasploit/model/authority/secunia_spec.rb +17 -0
  265. data/spec/lib/metasploit/model/authority/us_cert_vu_spec.rb +17 -0
  266. data/spec/lib/metasploit/model/authority/waraxe_spec.rb +51 -0
  267. data/spec/lib/metasploit/model/authority/zdi_spec.rb +21 -0
  268. data/spec/lib/metasploit/model/authority_spec.rb +10 -0
  269. data/spec/lib/metasploit/model/base_spec.rb +58 -0
  270. data/spec/lib/metasploit/model/configuration/autoload_spec.rb +165 -0
  271. data/spec/lib/metasploit/model/configuration/child_spec.rb +24 -0
  272. data/spec/lib/metasploit/model/configuration/error_spec.rb +5 -0
  273. data/spec/lib/metasploit/model/configuration/i18n_spec.rb +103 -0
  274. data/spec/lib/metasploit/model/configuration_spec.rb +106 -0
  275. data/spec/lib/metasploit/model/configured_spec.rb +41 -0
  276. data/spec/lib/metasploit/model/derivation/full_name_spec.rb +75 -0
  277. data/spec/lib/metasploit/model/derivation_spec.rb +217 -0
  278. data/spec/lib/metasploit/model/email_address_spec.rb +19 -0
  279. data/spec/lib/metasploit/model/engine_spec.rb +84 -0
  280. data/spec/lib/metasploit/model/file_spec.rb +43 -0
  281. data/spec/lib/metasploit/model/invalid_spec.rb +54 -0
  282. data/spec/lib/metasploit/model/module/action_spec.rb +6 -0
  283. data/spec/lib/metasploit/model/module/ancestor_spec.rb +6 -0
  284. data/spec/lib/metasploit/model/module/architecture_spec.rb +9 -0
  285. data/spec/lib/metasploit/model/module/author_spec.rb +6 -0
  286. data/spec/lib/metasploit/model/module/class_spec.rb +19 -0
  287. data/spec/lib/metasploit/model/module/handler_spec.rb +61 -0
  288. data/spec/lib/metasploit/model/module/instance_spec.rb +183 -0
  289. data/spec/lib/metasploit/model/module/path_spec.rb +6 -0
  290. data/spec/lib/metasploit/model/module/platform_spec.rb +9 -0
  291. data/spec/lib/metasploit/model/module/rank_spec.rb +29 -0
  292. data/spec/lib/metasploit/model/module/reference_spec.rb +9 -0
  293. data/spec/lib/metasploit/model/module/stance_spec.rb +30 -0
  294. data/spec/lib/metasploit/model/module/target/architecture_spec.rb +9 -0
  295. data/spec/lib/metasploit/model/module/target/platform_spec.rb +9 -0
  296. data/spec/lib/metasploit/model/module/target_spec.rb +9 -0
  297. data/spec/lib/metasploit/model/module/type_spec.rb +125 -0
  298. data/spec/lib/metasploit/model/nilify_blanks_spec.rb +156 -0
  299. data/spec/lib/metasploit/model/platform_spec.rb +100 -0
  300. data/spec/lib/metasploit/model/reference_spec.rb +21 -0
  301. data/spec/lib/metasploit/model/search/association_spec.rb +33 -0
  302. data/spec/lib/metasploit/model/search/attribute_spec.rb +99 -0
  303. data/spec/lib/metasploit/model/search/operation/integer/value_spec.rb +20 -0
  304. data/spec/lib/metasploit/model/search/operation/string/value_spec.rb +20 -0
  305. data/spec/lib/metasploit/model/search/operation_spec.rb +144 -0
  306. data/spec/lib/metasploit/model/search/operator/help_spec.rb +41 -0
  307. data/spec/lib/metasploit/model/search/with_spec.rb +81 -0
  308. data/spec/lib/metasploit/model/search_spec.rb +230 -0
  309. data/spec/lib/metasploit/model/spec/error_spec.rb +5 -0
  310. data/spec/lib/metasploit/model/spec/i18n_exception_handler_spec.rb +42 -0
  311. data/spec/lib/metasploit/model/spec/pathname_collision_spec.rb +55 -0
  312. data/spec/lib/metasploit/model/spec_spec.rb +114 -0
  313. data/spec/lib/metasploit/model/translation_spec.rb +82 -0
  314. data/spec/lib/metasploit/model/version_spec.rb +141 -0
  315. data/spec/lib/metasploit/model/visitation/visit_spec.rb +316 -0
  316. data/spec/lib/metasploit/model_spec.rb +68 -0
  317. data/spec/spec_helper.rb +48 -0
  318. data/spec/support/shared/contexts/metasploit/model/configuration.rb +11 -0
  319. data/spec/support/shared/contexts/metasploit/model/module/ancestor/contents/metasploit_module.rb +12 -0
  320. data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents.rb +10 -0
  321. data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents/metasploit_module.rb +15 -0
  322. data/spec/support/shared/contexts/metasploit/model/search/operator/union/children.rb +13 -0
  323. data/spec/support/shared/examples/derives.rb +115 -0
  324. data/spec/support/shared/examples/metasploit/model/architecture.rb +425 -0
  325. data/spec/support/shared/examples/metasploit/model/architecture/seed.rb +25 -0
  326. data/spec/support/shared/examples/metasploit/model/author.rb +27 -0
  327. data/spec/support/shared/examples/metasploit/model/authority.rb +124 -0
  328. data/spec/support/shared/examples/metasploit/model/authority/seed.rb +49 -0
  329. data/spec/support/shared/examples/metasploit/model/configuration/parent/child.rb +60 -0
  330. data/spec/support/shared/examples/metasploit/model/email_address.rb +220 -0
  331. data/spec/support/shared/examples/metasploit/model/module/action.rb +26 -0
  332. data/spec/support/shared/examples/metasploit/model/module/ancestor.rb +2004 -0
  333. data/spec/support/shared/examples/metasploit/model/module/ancestor/payload_factory.rb +63 -0
  334. data/spec/support/shared/examples/metasploit/model/module/architecture.rb +36 -0
  335. data/spec/support/shared/examples/metasploit/model/module/author.rb +29 -0
  336. data/spec/support/shared/examples/metasploit/model/module/class.rb +1514 -0
  337. data/spec/support/shared/examples/metasploit/model/module/handler.rb +21 -0
  338. data/spec/support/shared/examples/metasploit/model/module/instance.rb +1384 -0
  339. data/spec/support/shared/examples/metasploit/model/module/instance/class_methods.rb +537 -0
  340. data/spec/support/shared/examples/metasploit/model/module/instance/is_not_stanced_with_module_type.rb +22 -0
  341. data/spec/support/shared/examples/metasploit/model/module/instance/is_stanced_with_module_type.rb +38 -0
  342. data/spec/support/shared/examples/metasploit/model/module/instance/validates/dynamic_length_of.rb +131 -0
  343. data/spec/support/shared/examples/metasploit/model/module/path.rb +493 -0
  344. data/spec/support/shared/examples/metasploit/model/module/platform.rb +36 -0
  345. data/spec/support/shared/examples/metasploit/model/module/rank.rb +92 -0
  346. data/spec/support/shared/examples/metasploit/model/module/reference.rb +16 -0
  347. data/spec/support/shared/examples/metasploit/model/module/target.rb +29 -0
  348. data/spec/support/shared/examples/metasploit/model/module/target/architecture.rb +56 -0
  349. data/spec/support/shared/examples/metasploit/model/module/target/platform.rb +56 -0
  350. data/spec/support/shared/examples/metasploit/model/platform.rb +213 -0
  351. data/spec/support/shared/examples/metasploit/model/real_pathname.rb +29 -0
  352. data/spec/support/shared/examples/metasploit/model/reference.rb +410 -0
  353. data/spec/support/shared/examples/metasploit/model/search/operation/integer/value.rb +79 -0
  354. data/spec/support/shared/examples/metasploit/model/search/operation/string/value.rb +53 -0
  355. data/spec/support/shared/examples/metasploit/model/search/operator/help.rb +134 -0
  356. data/spec/support/shared/examples/metasploit/model/translation.rb +37 -0
  357. data/spec/support/shared/examples/search/query.rb +43 -0
  358. data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/app.rb +44 -0
  359. data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/authority.rb +60 -0
  360. data/spec/support/shared/examples/search_association.rb +13 -0
  361. data/spec/support/shared/examples/search_attribute.rb +27 -0
  362. data/spec/support/shared/examples/search_with.rb +36 -0
  363. data/spec/support/shared/matchers/allow_attribute.rb +17 -0
  364. data/spec/support/templates/metasploit/model/module/ancestors/_attributes.rb.erb +9 -0
  365. data/spec/support/templates/metasploit/model/module/ancestors/_methods.rb.erb +8 -0
  366. data/spec/support/templates/metasploit/model/module/ancestors/_validations.rb.erb +6 -0
  367. data/spec/support/templates/metasploit/model/module/ancestors/base.rb.erb +3 -0
  368. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_auxiliary.rb.erb +1 -0
  369. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_encoder.rb.erb +1 -0
  370. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_exploit.rb.erb +1 -0
  371. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_non_payload.rb.erb +5 -0
  372. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_nop.rb.erb +1 -0
  373. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_payload.rb.erb +4 -0
  374. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_post.rb.erb +1 -0
  375. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_handled.rb.erb +20 -0
  376. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_single.rb.erb +1 -0
  377. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stage.rb.erb +0 -0
  378. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stager.rb.erb +1 -0
  379. data/spec/support/templates/metasploit/model/module/classes/_methods.rb.erb +9 -0
  380. metadata +747 -0
@@ -0,0 +1,63 @@
1
+ shared_examples_for 'Metasploit::Model::Module::Ancestor payload factory' do |options={}|
2
+ options.assert_valid_keys(:handler_type)
3
+
4
+ should_have_handler_type = options[:handler_type]
5
+
6
+ its(:module_type) { should == 'payload' }
7
+
8
+ context 'contents' do
9
+ include_context 'Metasploit::Model::Module::Ancestor factory contents'
10
+
11
+ context 'metasploit_module' do
12
+ include_context 'Metasploit::Model::Module::Ancestor factory contents metasploit_module'
13
+
14
+ it { should be_a Module }
15
+ it { should_not be_a Class }
16
+
17
+ # nil means unknown/indeterminate. true or false cause specific testing
18
+ unless should_have_handler_type.nil?
19
+ if should_have_handler_type
20
+ method = :should
21
+ else
22
+ method = :should_not
23
+ end
24
+
25
+ it { send(method, respond_to(:handler_type_alias)) }
26
+
27
+ if should_have_handler_type
28
+ let(:handler_module) do
29
+ metasploit_module.handler_module
30
+ end
31
+
32
+ context 'handler_module' do
33
+ subject do
34
+ handler_module
35
+ end
36
+
37
+ it_should_behave_like 'Metasploit::Model::Module::Handler'
38
+
39
+ context 'handler_type' do
40
+ subject(:handler_type) do
41
+ handler_module.handler_type
42
+ end
43
+
44
+ it 'is different than Metasploit::Model::Module::Ancestor#handler_type' do
45
+ expect(handler_type).not_to eq(module_ancestor.handler_type)
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'handler_type_alias' do
51
+ subject(:handler_type_alias) do
52
+ metasploit_module.handler_type_alias
53
+ end
54
+
55
+ it 'should be #handler_type' do
56
+ handler_type_alias.should == module_ancestor.handler_type
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,36 @@
1
+ Metasploit::Model::Spec.shared_examples_for 'Module::Architecture' do
2
+ context 'factories' do
3
+ context module_architecture_factory.to_s do
4
+ subject(module_architecture_factory) do
5
+ FactoryGirl.build(module_architecture_factory)
6
+ end
7
+
8
+ it { should be_valid }
9
+
10
+ context '#module_instance' do
11
+ subject(:module_instance) do
12
+ send(module_architecture_factory).module_instance
13
+ end
14
+
15
+ it { should be_valid }
16
+
17
+ context '#module_architectures' do
18
+ subject(:module_architectures) do
19
+ module_instance.module_architectures
20
+ end
21
+
22
+ its(:length) { should == 1 }
23
+
24
+ it "should include #{module_architecture_factory}" do
25
+ expect(module_architectures).to include send(module_architecture_factory)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ context 'validations' do
33
+ it { should validate_presence_of :architecture }
34
+ it { should validate_presence_of :module_instance }
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ Metasploit::Model::Spec.shared_examples_for 'Module::Author' do
2
+ full_module_author_factory = "full_#{module_author_factory}"
3
+
4
+ context 'factories' do
5
+ context module_author_factory do
6
+ subject(module_author_factory) do
7
+ FactoryGirl.build(module_author_factory)
8
+ end
9
+
10
+ it { should be_valid }
11
+ end
12
+
13
+ context full_module_author_factory do
14
+ subject(full_module_author_factory) do
15
+ FactoryGirl.build(full_module_author_factory)
16
+ end
17
+
18
+ it { should be_valid }
19
+
20
+ its(:email_address) { should_not be_nil }
21
+ end
22
+ end
23
+
24
+ context 'validations' do
25
+ it { should validate_presence_of(:author) }
26
+ it { should validate_presence_of(:module_instance) }
27
+ it { should_not validate_presence_of(:email_address) }
28
+ end
29
+ end
@@ -0,0 +1,1514 @@
1
+ Metasploit::Model::Spec.shared_examples_for 'Module::Class' do
2
+ #
3
+ # Module::Ancestor factories
4
+ #
5
+
6
+ module_ancestor_factory = "#{factory_namespace}_module_ancestor"
7
+ payload_module_ancestor_factory = "payload_#{module_ancestor_factory}"
8
+ non_payload_module_ancestor_factory = "non_#{payload_module_ancestor_factory}"
9
+ single_payload_module_ancestor_factory = "single_#{payload_module_ancestor_factory}"
10
+ stage_payload_module_ancestor_factory = "stage_#{payload_module_ancestor_factory}"
11
+ stager_payload_module_ancestor_factory = "stager_#{payload_module_ancestor_factory}"
12
+
13
+ #
14
+ # Module::Class factories
15
+ #
16
+
17
+ module_class_factory = "#{factory_namespace}_module_class"
18
+
19
+ context 'CONSTANTS' do
20
+ context 'PAYLOAD_TYPES' do
21
+ subject(:payload_types) do
22
+ described_class::PAYLOAD_TYPES
23
+ end
24
+
25
+ it { should include('single') }
26
+ it { should include('staged') }
27
+ end
28
+
29
+ context 'STAGED_ANCESTOR_PAYLOAD_TYPES' do
30
+ subject(:staged_ancestor_payload_types) do
31
+ described_class::STAGED_ANCESTOR_PAYLOAD_TYPES
32
+ end
33
+
34
+ it { should include('stage') }
35
+ it { should include('stager') }
36
+ end
37
+ end
38
+
39
+ context 'derivations' do
40
+ context 'with module_type derived' do
41
+ before(:each) do
42
+ module_class.module_type = module_class.derived_module_type
43
+ end
44
+
45
+ context 'with payload_type derived' do
46
+ before(:each) do
47
+ module_class.payload_type = module_class.derived_payload_type
48
+ end
49
+
50
+ context 'with payload module_type' do
51
+ subject(:module_class) do
52
+ FactoryGirl.build(
53
+ module_class_factory,
54
+ :module_type => 'payload'
55
+ )
56
+ end
57
+
58
+ it_should_behave_like 'derives', :payload_type, :validates => true
59
+ it_should_behave_like 'derives', :reference_name, :validates => true
60
+
61
+ context 'with payload_type derived' do
62
+ before(:each) do
63
+ module_class.payload_type = module_class.derived_payload_type
64
+ end
65
+
66
+ context 'with reference_name derived' do
67
+ before(:each) do
68
+ module_class.reference_name = module_class.derived_reference_name
69
+ end
70
+
71
+ it_should_behave_like 'derives', :full_name, :validates => true
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ context 'without payload module_type' do
78
+ subject(:module_class) do
79
+ FactoryGirl.build(
80
+ module_class_factory,
81
+ :module_type => module_type
82
+ )
83
+ end
84
+
85
+ let(:module_type) do
86
+ FactoryGirl.generate :metasploit_model_non_payload_module_type
87
+ end
88
+
89
+ it_should_behave_like 'derives', :reference_name, :validates => true
90
+
91
+ context 'with reference_name derived' do
92
+ before(:each) do
93
+ module_class.reference_name = module_class.derived_reference_name
94
+ end
95
+
96
+ it_should_behave_like 'derives', :full_name, :validates => true
97
+ end
98
+ end
99
+ end
100
+
101
+ it_should_behave_like 'derives', :module_type, :validates => true
102
+ end
103
+
104
+ context 'search' do
105
+ context 'attributes' do
106
+ it_should_behave_like 'search_attribute', :full_name, :type => :string
107
+ it_should_behave_like 'search_attribute', :module_type, :type => :string
108
+ it_should_behave_like 'search_attribute', :payload_type, :type => :string
109
+ it_should_behave_like 'search_attribute', :reference_name, :type => :string
110
+ end
111
+ end
112
+
113
+ context 'factories' do
114
+ context module_class_factory do
115
+ subject(module_class_factory) do
116
+ FactoryGirl.build(module_class_factory)
117
+ end
118
+
119
+ it { should be_valid }
120
+
121
+ context '#ancestors' do
122
+ subject(:ancestors) do
123
+ send(module_class_factory).ancestors
124
+ end
125
+
126
+ context 'Metasploit::Model::Module::Ancestor#contents list' do
127
+ subject(:contents_list) do
128
+ ancestors.map(&:contents)
129
+ end
130
+
131
+ before(:each) do
132
+ # need to validate so that real_path is derived so contents can be read
133
+ ancestors.each(&:valid?)
134
+ end
135
+
136
+ context 'metasploit_modules' do
137
+ include_context 'Metasploit::Model::Module::Ancestor#contents metasploit_module'
138
+
139
+ subject(:metasploit_modules) do
140
+ namespace_modules.collect { |namespace_module|
141
+ namespace_module_metasploit_module(namespace_module)
142
+ }
143
+ end
144
+
145
+ let(:namespace_modules) do
146
+ ancestors.collect {
147
+ Module.new
148
+ }
149
+ end
150
+
151
+ before(:each) do
152
+ namespace_modules.zip(contents_list) do |namespace_module, contents|
153
+ namespace_module.module_eval(contents)
154
+ end
155
+ end
156
+
157
+ context 'rank_names' do
158
+ subject(:rank_names) do
159
+ metasploit_modules.collect { |metasploit_module|
160
+ metasploit_module.rank_name
161
+ }
162
+ end
163
+
164
+ it 'should match Metasploit::Model::Module::Class#rank Metasploit::Model:Module::Rank#name' do
165
+ rank_names.all? { |rank_name|
166
+ rank_name == send(module_class_factory).rank.name
167
+ }.should be_true
168
+ end
169
+ end
170
+
171
+ context 'rank_numbers' do
172
+ subject(:rank_numbers) do
173
+ metasploit_modules.collect { |metasploit_module|
174
+ metasploit_module.rank_number
175
+ }
176
+ end
177
+
178
+ it 'should match Metasploit::Model::Module::Class#rank Metasploit::Module::Module::Rank#number' do
179
+ rank_numbers.all? { |rank_number|
180
+ rank_number == send(module_class_factory).rank.number
181
+ }.should be_true
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ context 'module_type' do
189
+ subject(module_class_factory) do
190
+ FactoryGirl.build(
191
+ module_class_factory,
192
+ :module_type => module_type
193
+ )
194
+ end
195
+
196
+ context 'with payload' do
197
+ let(:module_type) do
198
+ 'payload'
199
+ end
200
+
201
+ it { should be_valid }
202
+
203
+ context 'with payload_type' do
204
+ subject(module_class_factory) do
205
+ FactoryGirl.build(
206
+ module_class_factory,
207
+ :module_type => module_type,
208
+ :payload_type => payload_type
209
+ )
210
+ end
211
+
212
+ context 'single' do
213
+ let(:payload_type) do
214
+ 'single'
215
+ end
216
+
217
+ it { should be_valid }
218
+ end
219
+
220
+ context 'staged' do
221
+ let(:payload_type) do
222
+ 'staged'
223
+ end
224
+
225
+ it { should be_valid }
226
+ end
227
+
228
+ context 'other' do
229
+ let(:payload_type) do
230
+ 'not_a_payload_type'
231
+ end
232
+
233
+ it 'should raise ArgumentError' do
234
+ expect {
235
+ send(module_class_factory)
236
+ }.to raise_error(ArgumentError)
237
+ end
238
+ end
239
+ end
240
+ end
241
+
242
+ context 'without payload' do
243
+ let(:module_type) do
244
+ FactoryGirl.generate :metasploit_model_non_payload_module_type
245
+ end
246
+
247
+ it { should be_valid }
248
+
249
+ its(:derived_module_type) { should == module_type }
250
+ end
251
+ end
252
+
253
+ context 'ancestors' do
254
+ subject(module_class_factory) do
255
+ FactoryGirl.build(
256
+ module_class_factory,
257
+ :ancestors => ancestors
258
+ )
259
+ end
260
+
261
+ context 'single payload' do
262
+ let!(:ancestors) do
263
+ [
264
+ FactoryGirl.create(single_payload_module_ancestor_factory)
265
+ ]
266
+ end
267
+
268
+ it { should be_valid }
269
+ end
270
+
271
+ context 'stage payload and stager payload' do
272
+ let!(:ancestors) do
273
+ [
274
+ FactoryGirl.create(stage_payload_module_ancestor_factory),
275
+ FactoryGirl.create(stager_payload_module_ancestor_factory)
276
+ ]
277
+ end
278
+
279
+ it { should be_valid }
280
+ end
281
+ end
282
+ end
283
+ end
284
+
285
+ context 'validations' do
286
+ context 'ancestors' do
287
+ context 'count' do
288
+ subject(:module_class) do
289
+ FactoryGirl.build(
290
+ module_class_factory,
291
+ :ancestors => ancestors,
292
+ :module_type => module_type,
293
+ :payload_type => payload_type
294
+ )
295
+ end
296
+
297
+ before(:each) do
298
+ # set explicitly so derivation doesn't cause other code path to run
299
+ module_class.module_type = module_type
300
+ end
301
+
302
+ context 'with payload module_type' do
303
+ let(:module_type) do
304
+ 'payload'
305
+ end
306
+
307
+ before(:each) do
308
+ # set explicitly so derivation doesn't cause other code path to run
309
+ module_class.payload_type = payload_type
310
+
311
+ module_class.valid?
312
+ end
313
+
314
+ context 'with single payload_type' do
315
+ let(:error) do
316
+ 'must have exactly one ancestor for single payload module class'
317
+ end
318
+
319
+ let(:payload_type) do
320
+ 'single'
321
+ end
322
+
323
+
324
+ context 'with 1 ancestor' do
325
+ let(:ancestors) do
326
+ [
327
+ FactoryGirl.create(single_payload_module_ancestor_factory)
328
+ ]
329
+ end
330
+
331
+ it 'should not record error on ancestors' do
332
+ module_class.errors[:ancestors].should_not include(error)
333
+ end
334
+ end
335
+
336
+ context 'without 1 ancestor' do
337
+ let(:ancestors) do
338
+ []
339
+ end
340
+
341
+ it 'should record error on ancestors' do
342
+ module_class.errors[:ancestors].should include(error)
343
+ end
344
+ end
345
+ end
346
+
347
+ context 'with staged payload_type' do
348
+ let(:error) do
349
+ 'must have exactly two ancestors (stager + stage) for staged payload module class'
350
+ end
351
+
352
+ let(:payload_type) do
353
+ 'staged'
354
+ end
355
+
356
+ context 'with 2 ancestors' do
357
+ let(:ancestors) do
358
+ [
359
+ FactoryGirl.create(stage_payload_module_ancestor_factory),
360
+ FactoryGirl.create(stager_payload_module_ancestor_factory)
361
+ ]
362
+ end
363
+
364
+ it 'should not record error on ancestors' do
365
+ module_class.errors[:ancestors].should_not include(error)
366
+ end
367
+ end
368
+
369
+ context 'without 2 ancestors' do
370
+ let(:ancestors) do
371
+ [
372
+ FactoryGirl.create(stage_payload_module_ancestor_factory)
373
+ ]
374
+ end
375
+
376
+ it 'should record error on ancestors' do
377
+ module_class.errors[:ancestors].should include(error)
378
+ end
379
+ end
380
+ end
381
+ end
382
+
383
+ context 'without payload module_type' do
384
+ let(:error) do
385
+ 'must have exactly one ancestor as a non-payload module class'
386
+ end
387
+
388
+ let(:module_type) do
389
+ FactoryGirl.generate :metasploit_model_non_payload_module_type
390
+ end
391
+
392
+ let(:payload_type) do
393
+ nil
394
+ end
395
+
396
+ before(:each) do
397
+ module_class.valid?
398
+ end
399
+
400
+ context 'with 1 ancestor' do
401
+ let(:ancestors) do
402
+ [
403
+ FactoryGirl.create(non_payload_module_ancestor_factory)
404
+ ]
405
+ end
406
+
407
+ it 'should not record error on ancestors' do
408
+ module_class.errors[:ancestors].should_not include(error)
409
+ end
410
+ end
411
+
412
+ context 'without 1 ancestor' do
413
+ let(:ancestors) do
414
+ module_class.errors[:ancestors].should include(error)
415
+ end
416
+ end
417
+ end
418
+ end
419
+
420
+ context 'module_types' do
421
+ context 'between Metasploit::Model::Module::Ancestor#module_type and Metasploit::Model::Module::Class#module_type' do
422
+ subject(:module_class) do
423
+ FactoryGirl.build(
424
+ module_class_factory,
425
+ :module_type => module_type,
426
+ :ancestors => ancestors
427
+ )
428
+ end
429
+
430
+ def error(module_class, ancestor)
431
+ "can contain ancestors only with same module_type (#{module_class.module_type}); " \
432
+ "#{ancestor.full_name} cannot be an ancestor due to its module_type (#{ancestor.module_type})"
433
+ end
434
+
435
+ before(:each) do
436
+ # Explicitly set module_type so its not derived, which could cause an alternate code path to be tested
437
+ module_class.module_type = module_type
438
+
439
+ module_class.valid?
440
+ end
441
+
442
+ context 'with module_type' do
443
+ let(:module_type) do
444
+ FactoryGirl.generate :metasploit_model_module_type
445
+ end
446
+
447
+ context 'with same Metasploit::Model::Module::Ancestor#module_type and Metasploit::Model::Module::Class#module_type' do
448
+ let(:ancestors) do
449
+ [
450
+ FactoryGirl.create(
451
+ module_ancestor_factory,
452
+ :module_type => module_type
453
+ )
454
+ ]
455
+ end
456
+
457
+ it 'should not record on ancestors' do
458
+ module_class.errors[:ancestors].should_not include(error(module_class, ancestors.first))
459
+ end
460
+ end
461
+
462
+ context 'without same Metasploit::Model::Module::Ancestor#module_type and Metasploit::Model::Module::Class#module_type' do
463
+ let(:ancestors) do
464
+ [
465
+ FactoryGirl.create(
466
+ module_ancestor_factory,
467
+ :module_type => 'exploit'
468
+ )
469
+ ]
470
+ end
471
+
472
+ let(:module_type) do
473
+ 'nop'
474
+ end
475
+
476
+ it 'should record error on ancestors' do
477
+ module_class.errors[:ancestors].should include(error(module_class, ancestors.first))
478
+ end
479
+ end
480
+ end
481
+
482
+ context 'without module_type' do
483
+ # with a nil module_type, module_type will be derived from
484
+ let(:ancestors) do
485
+ [
486
+ FactoryGirl.create(module_ancestor_factory),
487
+ FactoryGirl.create(module_ancestor_factory)
488
+ ]
489
+ end
490
+
491
+ let(:module_type) do
492
+ nil
493
+ end
494
+
495
+ it 'should not record errors on ancestors' do
496
+ ancestor_errors = module_class.errors[:ancestors]
497
+
498
+ ancestors.each do |ancestor|
499
+ ancestor_error = error(module_class, ancestor)
500
+
501
+ ancestor_errors.should_not include(ancestor_error)
502
+ end
503
+ end
504
+ end
505
+ end
506
+
507
+ context 'between Metasploit::Model::Module::Ancestor#module_types' do
508
+ subject(:module_class) do
509
+ FactoryGirl.build(
510
+ module_class_factory,
511
+ :ancestors => ancestors
512
+ )
513
+ end
514
+
515
+ let(:error) do
516
+ "can only contain ancestors with one module_type, " \
517
+ "but contains multiple module_types (#{module_type_set.sort.to_sentence})"
518
+ end
519
+
520
+ before(:each) do
521
+ module_class.valid?
522
+ end
523
+
524
+ context 'with same Metasploit::Model::Module::Ancestor#module_type' do
525
+ let(:ancestors) do
526
+ [
527
+ FactoryGirl.create(
528
+ module_ancestor_factory,
529
+ :module_type => module_type
530
+ ),
531
+ FactoryGirl.create(
532
+ module_ancestor_factory,
533
+ :module_type => module_type
534
+ )
535
+ ]
536
+ end
537
+
538
+ let(:module_type) do
539
+ FactoryGirl.generate :metasploit_model_module_type
540
+ end
541
+
542
+ let(:module_type_set) do
543
+ Set.new [module_type]
544
+ end
545
+
546
+ it 'should not record error on ancestors' do
547
+ module_class.errors[:ancestors].should_not include(error)
548
+ end
549
+ end
550
+
551
+ context 'without same Metasploit::Model::Module::Ancestor#module_type' do
552
+ let(:ancestors) do
553
+ module_type_set.collect { |module_type|
554
+ FactoryGirl.create(
555
+ module_ancestor_factory,
556
+ :module_type => module_type
557
+ )
558
+ }
559
+ end
560
+
561
+ let(:module_types) do
562
+ [
563
+ FactoryGirl.generate(:metasploit_model_module_type),
564
+ FactoryGirl.generate(:metasploit_model_module_type)
565
+ ]
566
+ end
567
+
568
+ let(:module_type_set) do
569
+ Set.new module_types
570
+ end
571
+
572
+ it 'should record error on ancestors' do
573
+ module_class.errors[:ancestors].should include(error)
574
+ end
575
+ end
576
+ end
577
+ end
578
+
579
+ context 'payload_types' do
580
+ subject(:module_class) do
581
+ FactoryGirl.build(
582
+ module_class_factory,
583
+ :ancestors => ancestors,
584
+ :module_type => module_type
585
+ )
586
+ end
587
+
588
+ before(:each) do
589
+ # explicitly set module_type so it is not derived from ancestors
590
+ module_class.module_type = module_type
591
+ end
592
+
593
+ context "with 'payload' Metasploit::Model::Module::Class#module_type" do
594
+ let(:module_type) do
595
+ 'payload'
596
+ end
597
+
598
+ let(:ancestors) do
599
+ [
600
+ ancestor
601
+ ]
602
+ end
603
+
604
+ context 'with Metasploit::Model::Module::Class#payload_type' do
605
+ before(:each) do
606
+ # Explicitly set payload_type so it is not derived from ancestors
607
+ module_class.payload_type = payload_type
608
+
609
+ module_class.valid?
610
+ end
611
+
612
+ context 'single' do
613
+ let(:error) do
614
+ "cannot have an ancestor (#{ancestor.full_name}) " \
615
+ "with payload_type (#{ancestor.payload_type}) " \
616
+ "for class payload_type (#{payload_type})"
617
+ end
618
+
619
+ let(:payload_type) do
620
+ 'single'
621
+ end
622
+
623
+ context "with 'single' Metasploit::Model::Module::Ancestor#payload_type" do
624
+ let(:ancestor) do
625
+ FactoryGirl.create(single_payload_module_ancestor_factory)
626
+ end
627
+
628
+ it 'should not record error on ancestors' do
629
+ module_class.errors[:ancestors].should_not include(error)
630
+ end
631
+ end
632
+
633
+ context "without 'single' Metasploit::Model::Module::Ancestor#payload_type" do
634
+ let(:ancestor) do
635
+ FactoryGirl.create(stage_payload_module_ancestor_factory)
636
+ end
637
+
638
+ it 'should record error on ancestors' do
639
+ module_class.errors[:ancestors].should include(error)
640
+ end
641
+ end
642
+ end
643
+
644
+ context 'staged' do
645
+ let(:payload_type) do
646
+ 'staged'
647
+ end
648
+
649
+ context "Metasploit::Model::Module::Ancestor#payload_type" do
650
+ let(:few_error) do
651
+ "needs exactly one ancestor with payload_type (#{ancestor_payload_type}), " \
652
+ "but there are none."
653
+ end
654
+
655
+ let(:many_error) do
656
+ "needs exactly one ancestor with payload_type (#{ancestor_payload_type}), " \
657
+ "but there are #{ancestors.count} (#{ancestors.map(&:full_name).sort.to_sentence})"
658
+ end
659
+
660
+ context 'single' do
661
+ context 'without zero' do
662
+ let(:ancestor) do
663
+ FactoryGirl.create(single_payload_module_ancestor_factory)
664
+ end
665
+
666
+ let(:ancestors) do
667
+ [
668
+ ancestor
669
+ ]
670
+ end
671
+
672
+ let(:error) do
673
+ "cannot have ancestors (#{ancestor.full_name}) " \
674
+ "with payload_type (#{ancestor.payload_type}) " \
675
+ "for class payload_type (#{payload_type}); " \
676
+ "only one stage and one stager ancestor is allowed"
677
+ end
678
+
679
+ it 'should record error on ancestors' do
680
+ module_class.valid?
681
+
682
+ module_class.errors[:ancestors].should include(error)
683
+ end
684
+ end
685
+ end
686
+
687
+ context 'stage' do
688
+ let(:ancestor_payload_type) do
689
+ 'stage'
690
+ end
691
+
692
+ context 'with < 1' do
693
+ # 1 stager and 0 stages, so stages count < 1
694
+ let(:ancestors) do
695
+ [
696
+ FactoryGirl.create(stager_payload_module_ancestor_factory)
697
+ ]
698
+ end
699
+
700
+ it 'should record error on ancestors' do
701
+ module_class.errors[:ancestors].should include(few_error)
702
+ end
703
+ end
704
+
705
+ context 'with 1' do
706
+ # 1 stager and 1 stage, so stages count == 1
707
+ let(:ancestors) do
708
+ [
709
+ FactoryGirl.create(stager_payload_module_ancestor_factory),
710
+ FactoryGirl.create(stage_payload_module_ancestor_factory)
711
+ ]
712
+ end
713
+
714
+ it 'should not record error on ancestors' do
715
+ module_class.errors[:ancestors].should_not include(few_error)
716
+ module_class.errors[:ancestors].should_not include(many_error)
717
+ end
718
+ end
719
+
720
+ context 'with > 1' do
721
+ # 0 stager, 2 stages, so stages count > 1
722
+ let(:ancestors) do
723
+ FactoryGirl.create_list(stage_payload_module_ancestor_factory, 2)
724
+ end
725
+
726
+ it 'should record error on ancestors' do
727
+ module_class.errors[:ancestors].should include(many_error)
728
+ end
729
+ end
730
+ end
731
+
732
+ context 'stager' do
733
+ let(:ancestor_payload_type) do
734
+ 'stager'
735
+ end
736
+
737
+ context 'with < 1' do
738
+ # 0 stager and 1 stages, so stagers count < 1
739
+ let(:ancestors) do
740
+ [
741
+ FactoryGirl.create(stage_payload_module_ancestor_factory)
742
+ ]
743
+ end
744
+
745
+ it 'should record error on ancestors' do
746
+ module_class.errors[:ancestors].should include(few_error)
747
+ end
748
+ end
749
+
750
+ context 'with 1' do
751
+ # 1 stager and 1 stage, so stagers count == 1
752
+ let(:ancestors) do
753
+ [
754
+ FactoryGirl.create(stager_payload_module_ancestor_factory),
755
+ FactoryGirl.create(stage_payload_module_ancestor_factory)
756
+ ]
757
+ end
758
+
759
+ it 'should not record error on ancestors' do
760
+ module_class.errors[:ancestors].should_not include(few_error)
761
+ module_class.errors[:ancestors].should_not include(many_error)
762
+ end
763
+ end
764
+
765
+ context 'with > 1' do
766
+ # 2 stagers, 0 stages, so stagers count > 1
767
+ let(:ancestors) do
768
+ FactoryGirl.create_list(stager_payload_module_ancestor_factory, 2)
769
+ end
770
+
771
+ it 'should record error on ancestors' do
772
+ module_class.errors[:ancestors].should include(many_error)
773
+ end
774
+ end
775
+ end
776
+ end
777
+ end
778
+ end
779
+ end
780
+
781
+ context "without 'payload' Metasploit::Model::Module::Class#module_type" do
782
+ let(:ancestors) do
783
+ [
784
+ ancestor
785
+ ]
786
+ end
787
+
788
+ let(:error) do
789
+ "cannot have an ancestor (#{ancestor.full_name}) " \
790
+ "with a payload_type (#{ancestor.payload_type}) " \
791
+ "for class module_type (#{module_type})"
792
+ end
793
+
794
+ let(:module_type) do
795
+ FactoryGirl.generate :metasploit_model_non_payload_module_type
796
+ end
797
+
798
+ before(:each) do
799
+ module_class.valid?
800
+ end
801
+
802
+ context 'with Metasploit::Model::Module::Ancestor#payload_type' do
803
+ let(:ancestor) do
804
+ FactoryGirl.create(payload_module_ancestor_factory)
805
+ end
806
+
807
+ it 'should record error on ancestors' do
808
+ module_class.errors[:ancestors].should include(error)
809
+ end
810
+ end
811
+
812
+ context 'without Metasploit::Model::Module::Ancestor#payload_type' do
813
+ let(:ancestor) do
814
+ FactoryGirl.create(non_payload_module_ancestor_factory)
815
+ end
816
+
817
+ it 'should not record error on ancestors' do
818
+ module_class.errors[:ancestors].should_not include(error)
819
+ end
820
+ end
821
+ end
822
+ end
823
+ end
824
+
825
+ context 'validates module_type inclusion in Metasploit::Model::Module::Ancestor::MODULE_TYPES' do
826
+ subject(:module_class) do
827
+ FactoryGirl.build(
828
+ module_class_factory,
829
+ :ancestors => [],
830
+ :module_type => module_type
831
+ )
832
+ end
833
+
834
+ let(:error) do
835
+ 'is not included in the list'
836
+ end
837
+
838
+ before(:each) do
839
+ module_class.module_type = module_type
840
+ end
841
+
842
+ Metasploit::Model::Module::Type::ALL.each do |context_module_type|
843
+ context "with #{context_module_type}" do
844
+ let(:module_type) do
845
+ context_module_type
846
+ end
847
+
848
+ it 'should not record error on module_type' do
849
+ module_class.valid?
850
+
851
+ module_class.errors[:module_type].should_not include(error)
852
+ end
853
+ end
854
+ end
855
+
856
+ context 'without module_type' do
857
+ let(:module_type) do
858
+ nil
859
+ end
860
+
861
+ it { should_not be_valid }
862
+
863
+ it 'should record error on module_type' do
864
+ module_class.valid?
865
+
866
+ module_class.errors[:module_type].should include(error)
867
+ end
868
+ end
869
+ end
870
+
871
+ context 'payload_type' do
872
+ subject(:module_class) do
873
+ FactoryGirl.build(
874
+ module_class_factory,
875
+ :module_type => module_type
876
+ )
877
+ end
878
+
879
+ before(:each) do
880
+ module_class.payload_type = payload_type
881
+ end
882
+
883
+ context 'with payload' do
884
+ let(:module_type) do
885
+ 'payload'
886
+ end
887
+
888
+ context 'with payload_type' do
889
+ subject(:module_class) do
890
+ FactoryGirl.build(
891
+ module_class_factory,
892
+ # Set explicitly so not derived from module_type and payload_type in factory, which will fail for the
893
+ # invalid payload_type test.
894
+ :ancestors => [],
895
+ :module_type => module_type,
896
+ :payload_type => payload_type
897
+ )
898
+ end
899
+
900
+ let(:error) do
901
+ 'is not in list'
902
+ end
903
+
904
+ before(:each) do
905
+ # Set explicitly so not derived
906
+ module_class.payload_type = payload_type
907
+ end
908
+
909
+ context 'single' do
910
+ let(:payload_type) do
911
+ 'single'
912
+ end
913
+
914
+ it 'should not record error' do
915
+ module_class.valid?
916
+
917
+ module_class.errors[:payload_type].should_not include(error)
918
+ end
919
+ end
920
+
921
+ context 'staged' do
922
+ let(:payload_type) do
923
+ 'staged'
924
+ end
925
+
926
+ it 'should not record error on payload_type' do
927
+ module_class.valid?
928
+
929
+ module_class.errors[:payload_type].should_not include(error)
930
+ end
931
+ end
932
+
933
+ context 'other' do
934
+ let(:payload_type) do
935
+ 'invalid_payload_type'
936
+ end
937
+
938
+ it 'should record error on payload_type' do
939
+ module_class.valid?
940
+
941
+ module_class.errors[:payload_type].should_not be_empty
942
+ end
943
+ end
944
+ end
945
+ end
946
+
947
+ context 'without payload' do
948
+ let(:error) do
949
+ 'must be nil'
950
+ end
951
+
952
+ let(:module_type) do
953
+ FactoryGirl.generate :metasploit_model_non_payload_module_type
954
+ end
955
+
956
+ before(:each) do
957
+ module_class.payload_type = payload_type
958
+ end
959
+
960
+ context 'with payload_type' do
961
+ let(:payload_type) do
962
+ FactoryGirl.generate :metasploit_model_module_class_payload_type
963
+ end
964
+
965
+ it 'should record error on payload_type' do
966
+ module_class.valid?
967
+
968
+ module_class.errors[:payload_type].should include(error)
969
+ end
970
+ end
971
+
972
+ context 'without payload_type' do
973
+ let(:payload_type) do
974
+ nil
975
+ end
976
+
977
+ it 'should not error on payload_type' do
978
+ module_class.valid?
979
+
980
+ module_class.errors[:payload_type].should_not include(error)
981
+ end
982
+
983
+ end
984
+ end
985
+ end
986
+
987
+ it { should validate_presence_of(:rank) }
988
+
989
+ context 'with nil derived_reference_name' do
990
+ before(:each) do
991
+ module_class.stub(:derived_reference_name => nil)
992
+ end
993
+
994
+ it { should validate_presence_of(:reference_name) }
995
+ end
996
+ end
997
+
998
+ context '#derived_module_type' do
999
+ subject(:derived_module_type) do
1000
+ module_class.derived_module_type
1001
+ end
1002
+
1003
+ context 'ancestors' do
1004
+ before(:each) do
1005
+ module_class.ancestors = ancestors
1006
+ end
1007
+
1008
+ context 'empty' do
1009
+ let(:ancestors) do
1010
+ []
1011
+ end
1012
+
1013
+ it { should be_nil }
1014
+ end
1015
+
1016
+ context 'non-empty' do
1017
+ context 'with same Metasploit::Model::Module::Ancestor#module_type' do
1018
+ let(:ancestors) do
1019
+ FactoryGirl.create_list(module_ancestor_factory, 2, :module_type => module_type)
1020
+ end
1021
+
1022
+ let(:module_type) do
1023
+ FactoryGirl.generate :metasploit_model_module_type
1024
+ end
1025
+
1026
+ it 'should return shared module_type' do
1027
+ derived_module_type.should == module_type
1028
+ end
1029
+ end
1030
+
1031
+ context 'with different Metasploit::Model::Module;:Ancestor#module_type' do
1032
+ let(:ancestors) do
1033
+ FactoryGirl.create_list(module_ancestor_factory, 2)
1034
+ end
1035
+
1036
+ it 'should return nil because there is no consensus' do
1037
+ derived_module_type.should be_nil
1038
+ end
1039
+ end
1040
+ end
1041
+ end
1042
+ end
1043
+
1044
+ context '#derived_payload_type' do
1045
+ subject(:derived_payload_type) do
1046
+ module_class.derived_payload_type
1047
+ end
1048
+
1049
+ before(:each) do
1050
+ module_class.module_type = module_type
1051
+ end
1052
+
1053
+ context 'with payload' do
1054
+ let(:module_type) do
1055
+ 'payload'
1056
+ end
1057
+
1058
+ before(:each) do
1059
+ module_class.ancestors = ancestors
1060
+ end
1061
+
1062
+ context 'with 1 ancestor' do
1063
+ let(:ancestors) do
1064
+ [
1065
+ FactoryGirl.create(
1066
+ module_ancestor_factory,
1067
+ :module_type => 'payload',
1068
+ :payload_type => payload_type
1069
+ )
1070
+ ]
1071
+ end
1072
+
1073
+ context 'with single' do
1074
+ let(:payload_type) do
1075
+ 'single'
1076
+ end
1077
+
1078
+ it { should == 'single' }
1079
+ end
1080
+
1081
+ context 'without single' do
1082
+ let(:payload_type) do
1083
+ 'stage'
1084
+ end
1085
+
1086
+ it { should be_nil }
1087
+ end
1088
+ end
1089
+
1090
+ context 'with 2 ancestors' do
1091
+ context 'with stager and stage' do
1092
+ let(:ancestors) do
1093
+ ['stager', 'stage'].collect { |payload_type|
1094
+ FactoryGirl.create(
1095
+ payload_module_ancestor_factory,
1096
+ :payload_type => payload_type
1097
+ )
1098
+ }
1099
+ end
1100
+
1101
+ it { should == 'staged' }
1102
+ end
1103
+
1104
+ context 'without stager and stage' do
1105
+ let(:ancestors) do
1106
+ FactoryGirl.create_list(
1107
+ payload_module_ancestor_factory,
1108
+ 2,
1109
+ :payload_type => 'stage'
1110
+ )
1111
+ end
1112
+
1113
+ it { should be_nil }
1114
+ end
1115
+ end
1116
+ end
1117
+
1118
+ context 'without payload' do
1119
+ let(:module_type) do
1120
+ FactoryGirl.generate :metasploit_model_non_payload_module_type
1121
+ end
1122
+ end
1123
+ end
1124
+
1125
+ context '#derived_reference_name' do
1126
+ subject(:derived_reference_name) do
1127
+ module_class.derived_reference_name
1128
+ end
1129
+
1130
+ before(:each) do
1131
+ module_class.module_type = module_type
1132
+ end
1133
+
1134
+ context 'with payload' do
1135
+ let(:module_type) do
1136
+ 'payload'
1137
+ end
1138
+
1139
+ before(:each) do
1140
+ module_class.payload_type = payload_type
1141
+ end
1142
+
1143
+ context 'with single' do
1144
+ let(:payload_type) do
1145
+ 'single'
1146
+ end
1147
+
1148
+ it 'should call #derived_single_payload_reference_name' do
1149
+ module_class.should_receive(:derived_single_payload_reference_name)
1150
+
1151
+ derived_reference_name
1152
+ end
1153
+ end
1154
+
1155
+ context 'with staged' do
1156
+ let(:payload_type) do
1157
+ 'staged'
1158
+ end
1159
+
1160
+ it 'should call #derived_staged_payload_reference_name' do
1161
+ module_class.should_receive(:derived_staged_payload_reference_name)
1162
+
1163
+ derived_reference_name
1164
+ end
1165
+ end
1166
+
1167
+ context 'without single or staged' do
1168
+ let(:payload_type) do
1169
+ 'invalid_payload_type'
1170
+ end
1171
+
1172
+ it { should be_nil }
1173
+ end
1174
+ end
1175
+
1176
+ context 'without payload' do
1177
+ let(:module_type) do
1178
+ FactoryGirl.generate :metasploit_model_non_payload_module_type
1179
+ end
1180
+
1181
+ before(:each) do
1182
+ module_class.ancestors = ancestors
1183
+ end
1184
+
1185
+ context 'with 1 ancestor' do
1186
+ let(:ancestor) do
1187
+ FactoryGirl.create(non_payload_module_ancestor_factory)
1188
+ end
1189
+
1190
+ let(:ancestors) do
1191
+ [
1192
+ ancestor
1193
+ ]
1194
+ end
1195
+
1196
+ it 'should return reference_name of ancestor' do
1197
+ derived_reference_name.should == ancestor.reference_name
1198
+ end
1199
+ end
1200
+
1201
+ context 'without 1 ancestor' do
1202
+ let(:ancestors) do
1203
+ FactoryGirl.create_list(module_ancestor_factory, 2)
1204
+ end
1205
+
1206
+ it { should be_nil }
1207
+ end
1208
+ end
1209
+ end
1210
+
1211
+ context '#derived_single_payload_reference_name' do
1212
+ subject(:derived_single_payload_reference_name) do
1213
+ module_class.send(:derived_single_payload_reference_name)
1214
+ end
1215
+
1216
+ before(:each) do
1217
+ module_class.ancestors = ancestors
1218
+ end
1219
+
1220
+ context 'with 1 ancestor' do
1221
+ let(:ancestor) do
1222
+ FactoryGirl.create(
1223
+ payload_module_ancestor_factory,
1224
+ :payload_type => payload_type
1225
+ )
1226
+ end
1227
+
1228
+ let(:ancestors) do
1229
+ [
1230
+ ancestor
1231
+ ]
1232
+ end
1233
+
1234
+ context 'with single' do
1235
+ let(:payload_type) do
1236
+ 'single'
1237
+ end
1238
+
1239
+ before(:each) do
1240
+ ancestor.reference_name = reference_name
1241
+ end
1242
+
1243
+ context 'with reference_name' do
1244
+ let(:payload_name) do
1245
+ 'payload/name'
1246
+ end
1247
+
1248
+ let(:payload_type_directory) do
1249
+ 'singles'
1250
+ end
1251
+
1252
+ let(:reference_name) do
1253
+ "#{payload_type_directory}/#{payload_name}"
1254
+ end
1255
+
1256
+ it 'should return Metasploit::Model::Module::Ancestor#payload_name' do
1257
+ expect(derived_single_payload_reference_name).to eq(payload_name)
1258
+ end
1259
+ end
1260
+
1261
+ context 'without reference_name' do
1262
+ let(:reference_name) do
1263
+ nil
1264
+ end
1265
+ end
1266
+
1267
+ end
1268
+
1269
+ context 'without single' do
1270
+ let(:payload_type) do
1271
+ 'stage'
1272
+ end
1273
+
1274
+ it { should be_nil }
1275
+ end
1276
+ end
1277
+
1278
+ context 'without 1 ancestor' do
1279
+ let(:ancestors) do
1280
+ []
1281
+ end
1282
+
1283
+ it { should be_nil }
1284
+ end
1285
+ end
1286
+
1287
+ context '#derived_staged_payload_reference_name' do
1288
+ subject(:derived_staged_payload_reference_name) do
1289
+ module_class.send(:derived_staged_payload_reference_name)
1290
+ end
1291
+
1292
+ before(:each) do
1293
+ module_class.ancestors = ancestors
1294
+ end
1295
+
1296
+ context 'with 2 ancestors' do
1297
+ context 'with 1 stage' do
1298
+ let(:stage_ancestor) do
1299
+ FactoryGirl.create(stage_payload_module_ancestor_factory)
1300
+ end
1301
+
1302
+ before(:each) do
1303
+ stage_ancestor.reference_name = stage_reference_name
1304
+ end
1305
+
1306
+ context 'with reference_name' do
1307
+ let(:stage_payload_name) do
1308
+ 'payload/name'
1309
+ end
1310
+
1311
+ let(:stage_reference_name) do
1312
+ "#{stage_type_directory}/#{stage_payload_name}"
1313
+ end
1314
+
1315
+ let(:stage_type_directory) do
1316
+ 'stages'
1317
+ end
1318
+
1319
+ context 'with 1 stager' do
1320
+ let(:ancestors) do
1321
+ [
1322
+ stager_ancestor,
1323
+ stage_ancestor
1324
+ ]
1325
+ end
1326
+
1327
+ let(:stager_ancestor) do
1328
+ FactoryGirl.create(stager_payload_module_ancestor_factory)
1329
+ end
1330
+
1331
+ before(:each) do
1332
+ stager_ancestor.handler_type = stager_handler_type
1333
+ end
1334
+
1335
+ context 'with handler_type' do
1336
+ let(:stager_handler_type) do
1337
+ FactoryGirl.generate :metasploit_model_module_handler_type
1338
+ end
1339
+
1340
+ it 'should be <stage.payload_name>/<stager.handler_type>' do
1341
+ expect(derived_staged_payload_reference_name).to eq("#{stage_payload_name}/#{stager_handler_type}")
1342
+ end
1343
+ end
1344
+
1345
+ context 'without handler_type' do
1346
+ let(:stager_handler_type) do
1347
+ nil
1348
+ end
1349
+
1350
+ it { should be_nil }
1351
+ end
1352
+ end
1353
+
1354
+ context 'without 1 stager' do
1355
+ let(:ancestors) do
1356
+ [
1357
+ stage_ancestor,
1358
+ FactoryGirl.create(single_payload_module_ancestor_factory)
1359
+ ]
1360
+ end
1361
+
1362
+ it { should be_nil }
1363
+ end
1364
+ end
1365
+
1366
+ context 'without reference_name' do
1367
+ let(:ancestors) do
1368
+ [
1369
+ FactoryGirl.create(stager_payload_module_ancestor_factory),
1370
+ stage_ancestor
1371
+ ]
1372
+ end
1373
+
1374
+ let(:stage_reference_name) do
1375
+ nil
1376
+ end
1377
+
1378
+ it { should be_nil }
1379
+ end
1380
+ end
1381
+
1382
+ context 'without 1 stage' do
1383
+ let(:ancestors) do
1384
+ FactoryGirl.create_list(stager_payload_module_ancestor_factory, 2)
1385
+ end
1386
+
1387
+ it { should be_nil }
1388
+ end
1389
+ end
1390
+
1391
+ context 'without 2 ancestors' do
1392
+ let(:ancestors) do
1393
+ FactoryGirl.create_list(module_ancestor_factory, 3)
1394
+ end
1395
+
1396
+ it { should be_nil }
1397
+ end
1398
+ end
1399
+
1400
+ context '#payload?' do
1401
+ subject(:payload?) do
1402
+ module_class.payload?
1403
+ end
1404
+
1405
+ # use new instead of factory so that payload? won't be called in the background to show this context supplies
1406
+ # coverage
1407
+ let(:module_class) do
1408
+ module_class_class.new
1409
+ end
1410
+
1411
+ before(:each) do
1412
+ module_class.module_type = module_type
1413
+ end
1414
+
1415
+ context 'with payload' do
1416
+ let(:module_type) do
1417
+ 'payload'
1418
+ end
1419
+
1420
+ it { should be_true }
1421
+ end
1422
+
1423
+ context 'without payload' do
1424
+ let(:module_type) do
1425
+ FactoryGirl.generate :metasploit_model_non_payload_module_type
1426
+ end
1427
+
1428
+ it { should be_false }
1429
+ end
1430
+ end
1431
+
1432
+ context '#staged_payload_type_count' do
1433
+ subject(:staged_payload_type_count) do
1434
+ module_class.send(
1435
+ :staged_payload_type_count,
1436
+ ancestors_by_payload_type,
1437
+ ancestor_payload_type
1438
+ )
1439
+ end
1440
+
1441
+ let(:ancestor_payload_type) do
1442
+ FactoryGirl.generate :metasploit_model_module_ancestor_payload_type
1443
+ end
1444
+
1445
+ before(:each) do
1446
+ staged_payload_type_count
1447
+ end
1448
+
1449
+ context 'with ancestors with payload_type' do
1450
+ context 'with 1' do
1451
+ let(:ancestors_by_payload_type) do
1452
+ {
1453
+ ancestor_payload_type => FactoryGirl.create_list(
1454
+ payload_module_ancestor_factory,
1455
+ 1,
1456
+ :payload_type => ancestor_payload_type
1457
+ )
1458
+ }
1459
+ end
1460
+
1461
+ it 'should not record error on ancestors' do
1462
+ module_class.errors[:ancestors].should be_empty
1463
+ end
1464
+ end
1465
+
1466
+ context 'without 1' do
1467
+ let(:ancestors_by_payload_type) do
1468
+ {
1469
+ ancestor_payload_type => payload_type_ancestors
1470
+ }
1471
+ end
1472
+
1473
+ let(:full_name_sentence) do
1474
+ payload_type_ancestors.map(&:full_name).sort.to_sentence
1475
+ end
1476
+
1477
+ let(:payload_type_ancestors) do
1478
+ FactoryGirl.create_list(
1479
+ payload_module_ancestor_factory,
1480
+ payload_type_ancestor_count,
1481
+ :payload_type => ancestor_payload_type
1482
+ )
1483
+ end
1484
+
1485
+ let(:payload_type_ancestor_count) do
1486
+ 2
1487
+ end
1488
+
1489
+ let(:error) do
1490
+ "needs exactly one ancestor with payload_type (#{ancestor_payload_type}), " \
1491
+ "but there are #{payload_type_ancestor_count} (#{full_name_sentence})"
1492
+ end
1493
+
1494
+ it 'should record error on ancestors' do
1495
+ module_class.errors[:ancestors].should include(error)
1496
+ end
1497
+ end
1498
+ end
1499
+
1500
+ context 'without ancestors with payload_type' do
1501
+ let(:ancestors_by_payload_type) do
1502
+ {}
1503
+ end
1504
+
1505
+ let(:error) do
1506
+ "needs exactly one ancestor with payload_type (#{ancestor_payload_type}), but there are none."
1507
+ end
1508
+
1509
+ it 'should record error on ancestors' do
1510
+ module_class.errors[:ancestors].should include(error)
1511
+ end
1512
+ end
1513
+ end
1514
+ end