oadr_lib_negative_test.rb 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  2. #
  3. # Copyright (c) 2016, Electric Power Research Institute (EPRI)
  4. # All rights reserved.
  5. #
  6. # OpenADR ("this software") is licensed under BSD 3-Clause license.
  7. #
  8. # Redistribution and use in source and binary forms, with or without modification,
  9. # are permitted provided that the following conditions are met:
  10. #
  11. # * Redistributions of source code must retain the above copyright notice, this
  12. # list of conditions and the following disclaimer.
  13. #
  14. # * Redistributions in binary form must reproduce the above copyright notice,
  15. # this list of conditions and the following disclaimer in the documentation
  16. # and/or other materials provided with the distribution.
  17. #
  18. # * Neither the name of EPRI nor the names of its contributors may
  19. # be used to endorse or promote products derived from this software without
  20. # specific prior written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  23. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  26. # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  31. # OF SUCH DAMAGE.
  32. #
  33. # This EPRI software incorporates work covered by the following copyright and permission
  34. # notices. You may not use these works except in compliance with their respective
  35. # licenses, which are provided below.
  36. #
  37. # These works are provided by the copyright holders and contributors "as is" and any express or
  38. # implied warranties, including, but not limited to, the implied warranties of merchantability
  39. # and fitness for a particular purpose are disclaimed.
  40. #
  41. #########################################################################################
  42. # MIT Licensed Libraries
  43. #########################################################################################
  44. #
  45. # * actionmailer 3.2.12 (http://www.rubyonrails.org) - Email composition, delivery, and receiving framework (part of Rails).
  46. # * actionpack 3.2.12 (http://www.rubyonrails.org) - Web-flow and rendering framework putting the VC in MVC (part of Rails).
  47. # * activemodel 3.2.12 (http://www.rubyonrails.org) - A toolkit for building modeling frameworks (part of Rails).
  48. # * activerecord 3.2.12 (http://www.rubyonrails.org) - Object-relational mapper framework (part of Rails).
  49. # * activeresource 3.2.12 (http://www.rubyonrails.org) - REST modeling framework (part of Rails).
  50. # * activesupport 3.2.12 (http://www.rubyonrails.org) - A toolkit of support libraries and Ruby core extensions extracted from the Rails framework.
  51. # * arel 3.0.2 (http://github.com/rails/arel) - Arel is a SQL AST manager for Ruby
  52. # * bootstrap-sass 3.1.1.0 (https://github.com/twbs/bootstrap-sass) - Twitter's Bootstrap, converted to Sass and ready to drop into Rails or Compass
  53. # * builder 3.0.4 (http://onestepback.org) - Builders for MarkUp.
  54. # * bundler 1.12.5 (http://bundler.io) - The best way to manage your application's dependencies
  55. # * capybara 2.4.4 (http://github.com/jnicklas/capybara) - Capybara aims to simplify the process of integration testing Rack applications, such as Rails, Sinatra or Merb
  56. # * coffee-rails 3.2.2 () - Coffee Script adapter for the Rails asset pipeline.
  57. # * coffee-script-source 1.6.3 (http://jashkenas.github.com/coffee-script/) - The CoffeeScript Compiler
  58. # * docile 1.1.5 (https://ms-ati.github.io/docile/) - Docile keeps your Ruby DSLs tame and well-behaved
  59. # * edn 1.0.0 () - 'edn implements a reader for Extensible Data Notation by Rich Hickey.'
  60. # * erubis 2.7.0 (http://www.kuwata-lab.com/erubis/) - a fast and extensible eRuby implementation which supports multi-language
  61. # * execjs 1.4.0 (https://github.com/sstephenson/execjs) - Run JavaScript code from Ruby
  62. # * factory_girl 4.5.0 (https://github.com/thoughtbot/factory_girl) - factory_girl provides a framework and DSL for defining and using model instance factories.
  63. # * factory_girl_rails 4.5.0 (http://github.com/thoughtbot/factory_girl_rails) - factory_girl_rails provides integration between factory_girl and rails 3
  64. # * gem-licenses 0.1.2 (http://github.com/dblock/gem-licenses) - List all gem licenses.
  65. # * hike 1.2.3 (http://github.com/sstephenson/hike) - Find files in a set of paths
  66. # * i18n 0.6.5 (http://github.com/svenfuchs/i18n) - New wave Internationalization support for Ruby
  67. # * jdbc-postgresql 9.2.1000 (https://github.com/rosenfeld/jdbc-postgresql) - PostgresSQL jdbc driver for JRuby
  68. # * journey 1.0.4 (http://github.com/rails/journey) - Journey is a router
  69. # * jquery-rails 3.0.4 (http://rubygems.org/gems/jquery-rails) - Use jQuery with Rails 3
  70. # * json-schema 2.6.2 (http://github.com/ruby-json-schema/json-schema/tree/master) - Ruby JSON Schema Validator
  71. # * mail 2.4.4 (http://github.com/mikel/mail) - Mail provides a nice Ruby DSL for making, sending and reading emails.
  72. # * metaclass 0.0.4 (http://github.com/floehopper/metaclass) - Adds a metaclass method to all Ruby objects
  73. # * mime-types 1.23 (http://mime-types.rubyforge.org/) - This library allows for the identification of a file's likely MIME content type
  74. # * mocha 1.1.0 (http://gofreerange.com/mocha/docs) - Mocking and stubbing library
  75. # * multi_json 1.7.9 (http://github.com/intridea/multi_json) - A common interface to multiple JSON libraries.
  76. # * nokogiri 1.6.5 (http://nokogiri.org) - Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser
  77. # * polyglot 0.3.3 (http://github.com/cjheath/polyglot) - Augment 'require' to load non-Ruby file types
  78. # * rack-test 0.6.2 (http://github.com/brynary/rack-test) - Simple testing API built on Rack
  79. # * railties 3.2.12 (http://www.rubyonrails.org) - Tools for creating, working with, and running Rails applications.
  80. # * rake 10.1.0 (http://rake.rubyforge.org) - Ruby based make-like utility.
  81. # * rspec-core 2.14.3 (http://github.com/rspec/rspec-core) - rspec-core-2.14.3
  82. # * rspec-expectations 2.14.0 (http://github.com/rspec/rspec-expectations) - rspec-expectations-2.14.0
  83. # * rspec-mocks 2.14.1 (http://github.com/rspec/rspec-mocks) - rspec-mocks-2.14.1
  84. # * rspec-rails 2.14.0 (http://github.com/rspec/rspec-rails) - rspec-rails-2.14.0
  85. # * sass 3.2.9 (http://sass-lang.com/) - A powerful but elegant CSS compiler that makes CSS fun again.
  86. # * sass-rails 3.2.6 () - Sass adapter for the Rails asset pipeline.
  87. # * simplecov 0.9.0 (http://github.com/colszowka/simplecov) - Code coverage for Ruby 1.9+ with a powerful configuration library and automatic merging of coverage across test suites
  88. # * spork 1.0.0rc3 (http://github.com/sporkrb/spork) - spork
  89. # * therubyrhino 2.0.2 (http://github.com/cowboyd/therubyrhino) - Embed the Rhino JavaScript interpreter into JRuby
  90. # * thor 0.18.1 (http://whatisthor.com/) - A scripting framework that replaces rake, sake and rubigen
  91. # * tilt 1.4.1 (http://github.com/rtomayko/tilt/) - Generic interface to multiple Ruby template engines
  92. # * treetop 1.4.14 (https://github.com/cjheath/treetop) - A Ruby-based text parsing and interpretation DSL
  93. # * uglifier 2.1.2 (http://github.com/lautis/uglifier) - Ruby wrapper for UglifyJS JavaScript compressor
  94. # * xpath 2.0.0 (http://github.com/jnicklas/xpath) - Generate XPath expressions from Ruby
  95. # * blankslate 2.1.2.4 (http://github.com/masover/blankslate) - BlankSlate extracted from Builder.
  96. # * bourbon 3.1.8 (https://github.com/thoughtbot/bourbon) - Bourbon Sass Mixins using SCSS syntax.
  97. # * coffee-script 2.2.0 (http://github.com/josh/ruby-coffee-script) - Ruby CoffeeScript Compiler
  98. # * diff-lcs 1.2.4 (http://diff-lcs.rubyforge.org/) - Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm
  99. # * jquery-ui-rails 4.0.3 (https://github.com/joliss/jquery-ui-rails) - jQuery UI packaged for the Rails asset pipeline
  100. # * parslet 1.4.0 (http://kschiess.github.com/parslet) - Parser construction library with great error reporting in Ruby.
  101. # * rack 1.4.5 (http://rack.github.com/) - a modular Ruby webserver interface
  102. # * rack-cache 1.2 (http://tomayko.com/src/rack-cache/) - HTTP Caching for Rack
  103. # * rack-ssl 1.3.3 (https://github.com/josh/rack-ssl) - Force SSL/TLS in your app.
  104. # * rails 3.2.12 (http://www.rubyonrails.org) - Full-stack web application framework.
  105. # * simplecov-html 0.8.0 (https://github.com/colszowka/simplecov-html) - Default HTML formatter for SimpleCov code coverage tool for ruby 1.9+
  106. # * tzinfo 0.3.37 (http://tzinfo.rubyforge.org/) - Daylight-savings aware timezone library
  107. # * warbler 1.4.0.beta1 (http://caldersphere.rubyforge.org/warbler) - Warbler chirpily constructs .war files of your Rails applications.
  108. #
  109. #########################################################################################
  110. # BSD Licensed Libraries
  111. #########################################################################################
  112. #
  113. # * activerecord-jdbc-adapter 1.2.9.1 (https://github.com/jruby/activerecord-jdbc-adapter) - Copyright (c) 2006-2012 Nick Sieger <nick@nicksieger.com>, Copyright (c) 2006-2008 Ola Bini <ola.bini@gmail.com>
  114. # * jdbc-postgres 9.2.1004 (https://github.com/jruby/activerecord-jdbc-adapter) - Copyright (c) 1997-2011, PostgreSQL Global Development Group
  115. # * d3js 3.5.16 (https://d3js.org/) Copyright (c) 2015 Mike Bostock
  116. #
  117. #########################################################################################
  118. # Ruby Licensed Libraries
  119. #########################################################################################
  120. #
  121. # * json 1.8.0 (http://json-jruby.rubyforge.org/) - JSON implementation for JRuby
  122. # * rubyzip 0.9.9 (http://github.com/aussiegeek/rubyzip) - rubyzip is a ruby module for reading and writing zip files
  123. # * httpclient 2.3.4.1 (http://github.com/nahi/httpclient) - gives something like the functionality of libwww-perl (LWP) in Ruby
  124. # * test-unit 2.5.5 (http://test-unit.rubyforge.org/) - test-unit - Improved version of Test::Unit bundled in Ruby 1.8.x.
  125. #
  126. #########################################################################################
  127. # Public domain - creative commons Licensed Libraries
  128. #########################################################################################
  129. #
  130. # * torquebox 3.1.2 (http://torquebox.org/) - TorqueBox Gem
  131. # * torquebox-cache 3.1.2 (http://torquebox.org/) - TorqueBox Cache Gem
  132. # * torquebox-configure 3.1.2 (http://torquebox.org/) - TorqueBox Configure Gem
  133. # * torquebox-core 3.1.2 (http://torquebox.org/) - TorqueBox Core Gem
  134. # * torquebox-messaging 3.1.2 (http://torquebox.org/) - TorqueBox Messaging Client
  135. # * torquebox-naming 3.1.2 (http://torquebox.org/) - TorqueBox Naming Client
  136. # * torquebox-rake-support 3.1.2 (http://torquebox.org/) - TorqueBox Rake Support
  137. # * torquebox-security 3.1.2 (http://torquebox.org/) - TorqueBox Security Gem
  138. # * torquebox-server 3.1.2 (http://torquebox.org/) - TorqueBox Server Gem
  139. # * torquebox-stomp 3.1.2 (http://torquebox.org/) - TorqueBox STOMP Support
  140. # * torquebox-transactions 3.1.2 (http://torquebox.org/) - TorqueBox Transactions Gem
  141. # * torquebox-web 3.1.2 (http://torquebox.org/) - TorqueBox Web Gem
  142. #
  143. #########################################################################################
  144. # Apache Licensed Libraries
  145. #########################################################################################
  146. #
  147. # * addressable 2.3.8 (https://github.com/sporkmonger/addressable) - URI Implementation
  148. # * bcrypt-ruby 3.0.1 (http://bcrypt-ruby.rubyforge.org) - OpenBSD's bcrypt() password hashing algorithm.
  149. # * database_cleaner 1.4.0 (http://github.com/bmabey/database_cleaner) - Strategies for cleaning databases. Can be used to ensure a clean state for testing.
  150. # * annotate 2.5.0 (http://github.com/ctran/annotate_models) - Annotates Rails Models, routes, fixtures, and others based on the database schema.
  151. # * nvd3 1.8.4 (http://nvd3.org/) Copeyright (c) 2014 Novus Partners - chart library based on d3js
  152. # * smack 3.3.1 (https://www.igniterealtime.org/projects/smack/) - XMPP library
  153. #
  154. #########################################################################################
  155. # LGPL
  156. #########################################################################################
  157. #
  158. # * jruby-1.7.4
  159. # * jruby-jars 1.7.4 (http://github.com/jruby/jruby/tree/master/gem/jruby-jars) - The core JRuby code and the JRuby stdlib as jar
  160. # ** JRuby is tri-licensed GPL, LGPL, and EPL.
  161. #
  162. #########################################################################################
  163. # MPL Licensed Libraries
  164. #########################################################################################
  165. #
  166. # * therubyrhino_jar 1.7.4 (http://github.com/cowboyd/therubyrhino) - Rhino's jars packed for therubyrhino
  167. #
  168. #########################################################################################
  169. # Artistic 2.0
  170. # * mime-types 1.23 (http://mime-types.rubyforge.org/) - This library allows for the identification of a file's likely MIME content type
  171. #
  172. #########################################################################################
  173. #
  174. #########################################################################################
  175. # GPL-2
  176. #########################################################################################
  177. # * mime-types 1.23 (http://mime-types.rubyforge.org/) - This library allows for the identification of a file's likely MIME content type
  178. #
  179. #########################################################################################
  180. # No License Given
  181. #########################################################################################
  182. #
  183. # * spork-testunit 0.0.8 (http://github.com/timcharper/spork-testunit) - spork-testunit
  184. # * sprockets 2.2.2 (http://getsprockets.org/) - Rack-based asset packaging system
  185. #
  186. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  187. require 'test_helper'
  188. require 'integration/helpers/flow_helper'
  189. #java_import Java::epri.oadr2b.lib.OadrRequestEvent
  190. #java_import Java::epri.oadr2b.lib.EiRequestEvent
  191. #java_import Java::epri.oadr2b.lib.OadrCreatedEvent
  192. #java_import Java::epri.oadr2b.lib.EiCreatedEvent
  193. class OadrLibNegativeTest < ActionDispatch::IntegrationTest
  194. fixtures :accounts, :vens, :vtn_parameters, :signal_types, :response_required_types, :market_contexts,
  195. :event_statuses, :groups, :resource_types
  196. include FlowHelper
  197. ########################################################
  198. setup do
  199. admin = accounts(:admin)
  200. admin.password ="testing"
  201. admin.password_confirmation = "testing"
  202. admin.save
  203. @ven = Ven.find_by_name("ven1")
  204. @ven.account_id = admin.id
  205. @ven.save
  206. registration = @ven.registrations.new
  207. registration.registration_id = "registrationid"
  208. registration.save
  209. @ven.registration = registration
  210. @ven.save
  211. # environment vars passed to the app from Apache when SSL is on
  212. @http_vars_valid = {'HTTP_HTTPS' => 'on', 'HTTP_SSL_CLIENT_S_DN_CN' => @ven.common_name}
  213. @http_vars_invalid = {'HTTP_HTTPS' => 'on', 'HTTP_SSL_CLIENT_S_DN_CN' => 'Invalid'}
  214. end
  215. ########################################################
  216. def validate_ei_reponse_b(xml, expected_code, oadr_object_function)
  217. oadr_payload = Marshalling20b.instance.unmarshal(@response.body)
  218. assert_not_nil oadr_payload.oadr_signed_object.public_send(oadr_object_function)
  219. ei_response = oadr_payload.oadr_signed_object.public_send(oadr_object_function).ei_response
  220. assert_not_nil ei_response
  221. assert_equal expected_code, ei_response.response_code
  222. end
  223. ########################################################
  224. def validate_ei_reponse_a(xml, expected_code, oadr_object_function)
  225. oadr_payload = Marshalling20a.instance.unmarshal(@response.body)
  226. # assert_equal Java::epri.oadr2b.lib.OadrResponse, oadr_payload.java_class
  227. assert_not_nil oadr_payload.ei_response
  228. assert_equal expected_code, oadr_payload.ei_response.response_code
  229. end
  230. ########################################################
  231. #
  232. # negative test scenarios for the oadr services
  233. # this function tests that each service properly rejects messages from:
  234. # 1) VEN with invalid CN in SSL cert
  235. # 2) VEN doesn't exist
  236. # 3) VEN isn't registered
  237. # each test is performed with and w/o SSL (SSL is simulated by setting the appropriate SSL headers)
  238. #
  239. # if the OADR XML messages had the VEN ID and request ID in the same location in each message,
  240. # it would be possible to write more generic service code to handle validation, which would in
  241. # in turn negate the need to test each service individually
  242. # perhaps the service code could be refactored to make the validation code happen before the service
  243. # touches the message, but I don't see a good way to do it
  244. def test_service_request(path, generate_request_method, validate_response_method, oadr_object_function, skip_registration_tests)
  245. xml = generate_request_method.call(@ven.ven_id)
  246. # invalid common name, but VEN exists
  247. post path, xml, @http_vars_invalid
  248. assert_response(200)
  249. validate_response_method.call(@response.body, "463", oadr_object_function)
  250. #
  251. # run tests with a VEN that doesn't exist
  252. #
  253. xml = generate_request_method.call("invalid ven id")
  254. # test with SSL enabled
  255. post path, xml, @http_vars_valid
  256. assert_response(200)
  257. validate_response_method.call(@response.body, "452", oadr_object_function)
  258. # test without SSL
  259. post path, xml
  260. assert_response(200)
  261. validate_response_method.call(@response.body, "452", oadr_object_function)
  262. # invalid common name
  263. post path, xml, @http_vars_invalid
  264. assert_response(200)
  265. validate_response_method.call(@response.body, "452", oadr_object_function)
  266. if not skip_registration_tests
  267. #
  268. # run the same tests with a VEN that isn't registered
  269. #
  270. xml = generate_request_method.call(@ven.ven_id)
  271. @ven.registration = nil
  272. @ven.save
  273. # test with SSL enabled
  274. post path, xml, @http_vars_valid
  275. assert_response(200)
  276. validate_response_method.call(@response.body, "463", oadr_object_function)
  277. # test without SSL
  278. post path, xml
  279. assert_response(200)
  280. validate_response_method.call(@response.body, "463", oadr_object_function)
  281. # invalid common name
  282. post path, xml, @http_vars_invalid
  283. assert_response(200)
  284. validate_response_method.call(@response.body, "463", oadr_object_function)
  285. end
  286. end
  287. ########################################################
  288. def generate_request_event_b(ven_id)
  289. request_event = Java::epri.oadr2b.lib.OadrRequestEvent.new
  290. request_event.schema_version = '2.0b'
  291. request_event.ei_request_event = Java::epri.oadr2b.lib.EiRequestEvent.new
  292. request_event.ei_request_event.request_id = SecureRandom.hex(10)
  293. request_event.ei_request_event.ven_id = ven_id
  294. request_event.ei_request_event.reply_limit = 10
  295. xml = Marshalling20b.instance.marshal_and_wrap(request_event, 'set_oadr_request_event')
  296. end
  297. ########################################################
  298. def generate_request_event_a(ven_id)
  299. request_event = Java::epri.oadr2a.lib.OadrRequestEvent.new
  300. request_event.ei_request_event = Java::epri.oadr2a.lib.EiRequestEvent.new
  301. request_event.ei_request_event.request_id = SecureRandom.hex(10)
  302. request_event.ei_request_event.ven_id = ven_id
  303. request_event.ei_request_event.reply_limit = 10
  304. xml = Marshalling20a.instance.marshal(request_event)
  305. end
  306. ########################################################
  307. def generate_created_event_b(ven_id)
  308. created_event = Java::epri.oadr2b.lib.OadrCreatedEvent.new
  309. created_event.ei_created_event = Java::epri.oadr2b.lib.EiCreatedEvent.new
  310. created_event.ei_created_event.ven_id = ven_id
  311. created_event.ei_created_event.ei_response = Oadr2bFactory.create_response("200", "OK", "")
  312. xml = Marshalling20b.instance.marshal_and_wrap(created_event, 'set_oadr_created_event')
  313. end
  314. ########################################################
  315. def generate_created_event_a(ven_id)
  316. created_event = Java::epri.oadr2a.lib.OadrCreatedEvent.new
  317. created_event.ei_created_event = Java::epri.oadr2a.lib.EiCreatedEvent.new
  318. created_event.ei_created_event.ven_id = ven_id
  319. created_event.ei_created_event.ei_response = Oadr2aFactory.create_response("200", "OK", "")
  320. xml = Marshalling20a.instance.marshal(created_event)
  321. end
  322. ########################################################
  323. test "neg request event b" do
  324. # profile b
  325. test_service_request(oadr20b_event_path, method(:generate_request_event_b), method(:validate_ei_reponse_b), 'oadr_distribute_event', false)
  326. end
  327. ########################################################
  328. test "neg created event b" do
  329. test_service_request(oadr20b_event_path, method(:generate_created_event_b), method(:validate_ei_reponse_b), 'oadr_response', false)
  330. end
  331. ########################################################
  332. test "neg request event a" do
  333. # profile a
  334. test_service_request(oadr20a_event_path, method(:generate_request_event_a), method(:validate_ei_reponse_a), '', true)
  335. end
  336. ########################################################
  337. test "neg created event a" do
  338. test_service_request(oadr20a_event_path, method(:generate_created_event_a), method(:validate_ei_reponse_a), '', true)
  339. end
  340. ########################################################
  341. def generate_cancel_opt_schedule(ven_id)
  342. cancel_opt = Java::epri.oadr2b.lib.OadrCancelOpt.new
  343. cancel_opt.ven_id = ven_id
  344. xml = Marshalling20b.instance.marshal_and_wrap(cancel_opt, 'set_oadr_cancel_opt')
  345. end
  346. ########################################################
  347. #
  348. # 1) send the wrong message type to a service (opt message to the event service)
  349. # 2) send a malformed XML message
  350. #
  351. test "invalid message" do
  352. # send an opt message to the event service
  353. xml = generate_cancel_opt_schedule("ven_id")
  354. post oadr20b_event_path, xml
  355. validate_ei_reponse_b(@response.body, "500", 'oadr_response')
  356. # send invalid XML
  357. xml = "malformed xml"
  358. post oadr20b_event_path, xml
  359. validate_ei_reponse_b(@response.body, "500", 'oadr_response')
  360. #
  361. # profile a
  362. #
  363. xml = generate_cancel_opt_schedule("ven_id")
  364. post oadr20a_event_path, xml
  365. validate_ei_reponse_a(@response.body, "500", '')
  366. # send invalid XML
  367. xml = "malformed xml"
  368. post oadr20a_event_path, xml
  369. validate_ei_reponse_a(@response.body, "500", '')
  370. end
  371. ########################################################
  372. def generate_create_opt_schedule(ven_id)
  373. create_opt = Java::epri.oadr2b.lib.OadrCreateOpt.new
  374. create_opt.ven_id = ven_id
  375. xml = Marshalling20b.instance.marshal_and_wrap(create_opt, 'set_oadr_create_opt')
  376. end
  377. ########################################################
  378. def generate_create_opt_event(ven_id)
  379. create_opt = Java::epri.oadr2b.lib.OadrCreateOpt.new
  380. create_opt.ven_id = ven_id
  381. create_opt.qualified_event_id = QualifiedEventID.new
  382. create_opt.qualified_event_id.event_id = "eventid"
  383. create_opt.qualified_event_id.modification_number = 0
  384. xml = Marshalling20b.instance.marshal_and_wrap(create_opt, 'set_oadr_create_opt')
  385. end
  386. ########################################################
  387. test "neg cancel opt schedule" do
  388. test_service_request(oadr20b_opt_path, method(:generate_cancel_opt_schedule), method(:validate_ei_reponse_b), 'oadr_canceled_opt', false)
  389. end
  390. ########################################################
  391. test "neg create opt schedule" do
  392. test_service_request(oadr20b_opt_path, method(:generate_create_opt_schedule), method(:validate_ei_reponse_b), 'oadr_created_opt', false)
  393. end
  394. ########################################################
  395. test "neg create opt event" do
  396. test_service_request(oadr20b_opt_path, method(:generate_create_opt_event), method(:validate_ei_reponse_b), 'oadr_created_opt', false)
  397. end
  398. ########################################################
  399. def generate_poll(ven_id)
  400. poll = Java::epri.oadr2b.lib.OadrPoll.new
  401. poll.ven_id = ven_id
  402. xml = Marshalling20b.instance.marshal_and_wrap(poll, 'set_oadr_poll')
  403. end
  404. ########################################################
  405. test "neg poll" do
  406. test_service_request(oadr20b_poll_path, method(:generate_poll), method(:validate_ei_reponse_b), 'oadr_response', false)
  407. end
  408. ########################################################
  409. def generate_query_registration
  410. query_registration = Java::epri.oadr2b.lib.OadrQueryRegistration.new
  411. query_registration.request_id = "request_id"
  412. xml = Marshalling20b.instance.marshal_and_wrap(query_registration, 'set_oadr_query_registration')
  413. end
  414. ########################################################
  415. test "neg query registration" do
  416. xml = generate_query_registration
  417. #
  418. # test with SSL enabled
  419. #
  420. post oadr20b_register_path, xml, @http_vars_valid
  421. assert_response(200)
  422. payload = Marshalling20b.instance.unmarshal(@response.body)
  423. assert_equal @ven.ven_id, payload.oadr_signed_object.oadr_created_party_registration.ven_id
  424. assert_equal @ven.registration.registration_id, payload.oadr_signed_object.oadr_created_party_registration.registration_id
  425. #
  426. # test with SSL enabled invalid CN
  427. #
  428. post oadr20b_register_path, xml, @http_vars_invalid
  429. assert_response(200)
  430. validate_ei_reponse_b(@response.body, "452", 'oadr_created_party_registration')
  431. # test without SSL
  432. # should return a valid createdPartyRegistration message w/o registration or VEN id
  433. # the service uses the SSL cert to lookup the VEN and place the registration info
  434. # in the message if the VEN is registered
  435. post oadr20b_register_path, xml
  436. assert_response(200)
  437. payload = Marshalling20b.instance.unmarshal(@response.body)
  438. assert_equal '', payload.oadr_signed_object.oadr_created_party_registration.ven_id
  439. assert_equal '', payload.oadr_signed_object.oadr_created_party_registration.registration_id
  440. #
  441. # test with SSL enabled, ven not registered
  442. #
  443. @ven.registration = nil
  444. @ven.save
  445. post oadr20b_register_path, xml, @http_vars_valid
  446. assert_response(200)
  447. payload = Marshalling20b.instance.unmarshal(@response.body)
  448. assert_equal '', payload.oadr_signed_object.oadr_created_party_registration.ven_id
  449. assert_equal '', payload.oadr_signed_object.oadr_created_party_registration.registration_id
  450. end
  451. ########################################################
  452. def generate_create_registration(ven_name, ven_id=nil)
  453. create_registration = Java::epri.oadr2b.lib.OadrCreatePartyRegistration.new
  454. create_registration.oadr_ven_name = ven_name
  455. create_registration.ven_id = ven_id if not ven_id.nil?
  456. create_registration.oadr_transport_name = Java::epri.oadr2b.lib.OadrTransportType::SIMPLE_HTTP
  457. xml = Marshalling20b.instance.marshal_and_wrap(create_registration, 'set_oadr_create_party_registration')
  458. end
  459. ########################################################
  460. test "neg create registration" do
  461. #
  462. # w/SSL, invalid CN, valid ven_name
  463. #
  464. xml = generate_create_registration(@ven.name)
  465. post oadr20b_register_path, xml, @http_vars_invalid
  466. assert_response(200)
  467. validate_ei_reponse_b(@response.body, "452", 'oadr_created_party_registration')
  468. #
  469. # w/SSL, invalid CN, invalid ven_name
  470. #
  471. xml = generate_create_registration("invalid ven name")
  472. post oadr20b_register_path, xml, @http_vars_invalid
  473. assert_response(200)
  474. validate_ei_reponse_b(@response.body, "452", 'oadr_created_party_registration')
  475. #
  476. # w/SSL, CN VEN doesn't match ven.name
  477. # this ven name must match an existing VEN
  478. #
  479. xml = generate_create_registration(vens(:ven2).name)
  480. post oadr20b_register_path, xml, @http_vars_valid
  481. assert_response(200)
  482. validate_ei_reponse_b(@response.body, "463", 'oadr_created_party_registration')
  483. end
  484. ########################################################
  485. #
  486. # test registration scenarios w/o a ven name (ven name is optional)
  487. # this is actually a positive test since registration should succeed
  488. #
  489. test "neg create registration no name" do
  490. #
  491. # w/SSL, invalid CN, valid ven_name
  492. #
  493. xml = generate_create_registration(nil, @ven.ven_id)
  494. post oadr20b_register_path, xml, @http_vars_valid
  495. assert_response(200)
  496. validate_ei_reponse_b(@response.body, "200", 'oadr_created_party_registration')
  497. # if the name and registration are nil, the server should rely on the VEN lookup based on the certificate (common_name)
  498. xml = generate_create_registration(nil, nil)
  499. post oadr20b_register_path, xml, @http_vars_valid
  500. assert_response(200)
  501. validate_ei_reponse_b(@response.body, "200", 'oadr_created_party_registration')
  502. end
  503. ########################################################
  504. def generate_canceled_registration(ven_id)
  505. canceled_registration = Java::epri.oadr2b.lib.OadrCanceledPartyRegistration.new
  506. canceled_registration.ven_id = ven_id
  507. xml = Marshalling20b.instance.marshal_and_wrap(canceled_registration, 'set_oadr_canceled_party_registration')
  508. end
  509. ########################################################
  510. test "neg canceled registration" do
  511. test_service_request(oadr20b_register_path, method(:generate_canceled_registration), method(:validate_ei_reponse_b), 'oadr_response', false)
  512. end
  513. ########################################################
  514. def generate_cancel_registration(ven_id)
  515. cancel_registration = Java::epri.oadr2b.lib.OadrCancelPartyRegistration.new
  516. cancel_registration.ven_id = ven_id
  517. xml = Marshalling20b.instance.marshal_and_wrap(cancel_registration, 'set_oadr_cancel_party_registration')
  518. end
  519. ########################################################
  520. test "neg cancel registration" do
  521. test_service_request(oadr20b_register_path, method(:generate_cancel_registration), method(:validate_ei_reponse_b), 'oadr_canceled_party_registration', false)
  522. end
  523. ########################################################
  524. def generate_update_report(ven_id)
  525. update_report = Java::epri.oadr2b.lib.OadrUpdateReport.new
  526. update_report.ven_id = ven_id
  527. update_report.request_id = "request_id"
  528. xml = Marshalling20b.instance.marshal_and_wrap(update_report, 'set_oadr_update_report')
  529. end
  530. ########################################################
  531. test "neg update report" do
  532. test_service_request(oadr20b_report_path, method(:generate_update_report), method(:validate_ei_reponse_b), 'oadr_updated_report', false)
  533. end
  534. ########################################################
  535. def generate_created_report(ven_id)
  536. created_report = Java::epri.oadr2b.lib.OadrCreatedReport.new
  537. created_report.ven_id = ven_id
  538. created_report.ei_response = Oadr2bFactory.create_response("200", "OK", "request_id")
  539. xml = Marshalling20b.instance.marshal_and_wrap(created_report, 'set_oadr_created_report')
  540. end
  541. ########################################################
  542. test "neg created report" do
  543. test_service_request(oadr20b_report_path, method(:generate_created_report), method(:validate_ei_reponse_b), 'oadr_response', false)
  544. end
  545. ########################################################
  546. def generate_canceled_report(ven_id)
  547. canceled_report = Java::epri.oadr2b.lib.OadrCanceledReport.new
  548. canceled_report.ven_id = ven_id
  549. canceled_report.ei_response = Oadr2bFactory.create_response("200", "OK", "request_id")
  550. xml = Marshalling20b.instance.marshal_and_wrap(canceled_report, 'set_oadr_canceled_report')
  551. end
  552. ########################################################
  553. test "neg canceled report" do
  554. test_service_request(oadr20b_report_path, method(:generate_canceled_report), method(:validate_ei_reponse_b), 'oadr_response', false)
  555. end
  556. ########################################################
  557. def generate_register_report(ven_id)
  558. register_report = Java::epri.oadr2b.lib.OadrRegisterReport.new
  559. register_report.ven_id = ven_id
  560. register_report.request_id = "request_id"
  561. xml = Marshalling20b.instance.marshal_and_wrap(register_report, 'set_oadr_register_report')
  562. end
  563. ########################################################
  564. test "neg register report" do
  565. test_service_request(oadr20b_report_path, method(:generate_register_report), method(:validate_ei_reponse_b), 'oadr_registered_report', false)
  566. end
  567. ########################################################
  568. def generate_registered_report(ven_id)
  569. registered_report = Java::epri.oadr2b.lib.OadrRegisteredReport.new
  570. registered_report.ven_id = ven_id
  571. registered_report.ei_response = Oadr2bFactory.create_response("200", "OK", "request_id")
  572. xml = Marshalling20b.instance.marshal_and_wrap(registered_report, 'set_oadr_registered_report')
  573. end
  574. ########################################################
  575. test "neg registered report" do
  576. test_service_request(oadr20b_report_path, method(:generate_registered_report), method(:validate_ei_reponse_b), 'oadr_response', false)
  577. end
  578. end