Class: IMS::LTI::Services::ToolProxyValidator
- Inherits:
-
Object
- Object
- IMS::LTI::Services::ToolProxyValidator
- Defined in:
- lib/ims/lti/services/tool_proxy_validator.rb
Instance Attribute Summary collapse
-
#tool_proxy ⇒ Object
readonly
Returns the value of attribute tool_proxy.
Instance Method Summary collapse
- #capabilities_offered ⇒ Object
- #errors ⇒ Object
-
#initialize(tool_proxy) ⇒ ToolProxyValidator
constructor
A new instance of ToolProxyValidator.
- #invalid_capabilities ⇒ Object
- #invalid_message_handlers ⇒ Object
- #invalid_security_contract ⇒ Object
- #invalid_security_profiles ⇒ Object
- #invalid_services ⇒ Object
- #tool_consumer_profile ⇒ Object
- #tool_consumer_profile=(tcp) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(tool_proxy) ⇒ ToolProxyValidator
Returns a new instance of ToolProxyValidator.
6 7 8 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 6 def initialize(tool_proxy) @tool_proxy = tool_proxy end |
Instance Attribute Details
#tool_proxy ⇒ Object (readonly)
Returns the value of attribute tool_proxy.
4 5 6 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 4 def tool_proxy @tool_proxy end |
Instance Method Details
#capabilities_offered ⇒ Object
27 28 29 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 27 def capabilities_offered tool_consumer_profile.capabilities_offered end |
#errors ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 105 def errors ret_val = {} ret_val[:invalid_security_contract] = invalid_security_contract unless invalid_security_contract.empty? ret_val[:invalid_capabilities] = invalid_capabilities unless invalid_capabilities.empty? ret_val[:invalid_message_handlers] = unless .empty? ret_val[:invalid_services] = invalid_services unless invalid_services.empty? ret_val[:invalid_security_profiles] = invalid_security_profiles unless invalid_security_profiles.empty? ret_val end |
#invalid_capabilities ⇒ Object
66 67 68 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 66 def invalid_capabilities tool_proxy.enabled_capabilities - capabilities_offered end |
#invalid_message_handlers ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 55 def ret_val = {} tool_profile = tool_proxy.tool_profile #singleton_message_handlers = tool_profile.messages invalid_rhs = validate_resource_handlers(tool_profile.resource_handlers) ret_val[:resource_handlers] = invalid_rhs unless invalid_rhs.empty? = (tool_profile.) ret_val[:singleton_message_handlers] = unless .empty? ret_val end |
#invalid_security_contract ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 70 def invalid_security_contract ret_val = {} is_split_secret_capable = tool_proxy.enabled_capabilities.include?('Security.splitSecret') has_shared_secret = tool_proxy.security_contract.shared_secret != nil && !tool_proxy.security_contract.shared_secret.empty? has_split_secret = tool_proxy.security_contract.tp_half_shared_secret != nil && !tool_proxy.security_contract.tp_half_shared_secret.empty? if is_split_secret_capable ret_val[:missing_secret] = :tp_half_shared_secret unless has_split_secret ret_val[:invalid_secret_type] = :shared_secret if has_shared_secret else ret_val[:missing_secret] = :shared_secret unless has_shared_secret ret_val[:invalid_secret_type] = :tp_half_shared_secret if has_split_secret end ret_val end |
#invalid_security_profiles ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 88 def invalid_security_profiles security_profiles = tool_proxy.tool_profile.security_profiles array = security_profiles.each_with_object([]) do |sp, array| tcp_sp = tool_consumer_profile.security_profile_by_name(security_profile_name: sp.security_profile_name) if tcp_sp supported_algorithms = sp.digest_algorithms & tcp_sp.digest_algorithms unsupported_algorithms = sp.digest_algorithms - supported_algorithms unless unsupported_algorithms.empty? array << { name: sp.security_profile_name, algorithms: unsupported_algorithms } end else array << { name: sp.security_profile_name } end end array end |
#invalid_services ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 31 def invalid_services services = tool_proxy.security_contract.services services_used = services.each_with_object({}) do |s, hash| hash[s.service.split('#').last.strip] = s.actions hash end services_offered = tool_consumer_profile.services_offered.each_with_object({}) do |s, hash| hash[s.id.split(':').last.split('#').last.strip] = s.actions hash end invalid_services = services_used.each_with_object({}) do |(id, actions), hash| if services_offered.keys.include?(id) actions_used = normalize_strings(*services_offered[id]) actions_offered = normalize_strings(*actions) invalid_actions = actions_offered - actions_used hash[id] = invalid_actions unless invalid_actions.empty? else hash[id] = actions end hash end invalid_services end |
#tool_consumer_profile ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 10 def tool_consumer_profile return @tool_consumer_profile if @tool_consumer_profile connection = Faraday.new response = connection.get(tool_proxy.tool_consumer_profile) @tool_consumer_profile = IMS::LTI::Models::ToolConsumerProfile.new.from_json(response.body) @tool_consumer_profile end |
#tool_consumer_profile=(tcp) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 19 def tool_consumer_profile=(tcp) tcp = IMS::LTI::Models::ToolConsumerProfile.from_json(tcp) unless tcp.is_a?(IMS::LTI::Models::ToolConsumerProfile) if tool_proxy.tool_consumer_profile != tcp.id raise IMS::LTI::Errors::InvalidToolConsumerProfile, "Tool Consumer Profile @id doesn't match the Tool Proxy" end @tool_consumer_profile = tcp end |
#valid? ⇒ Boolean
115 116 117 |
# File 'lib/ims/lti/services/tool_proxy_validator.rb', line 115 def valid? errors.keys.empty? end |