ims-lti 2.0.0.beta.29 → 2.0.0.beta.30

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d34295d75aca72702d27339dca8e30bcfc4b5f42
4
- data.tar.gz: e346638b48ba8f6bb59e3ef619702cfba4ff3a3d
3
+ metadata.gz: 6c2af2a10db5b2ed1ba1c946bdbfb7b07bd4d733
4
+ data.tar.gz: 00b8c3301b940f227c5e694a93a9e2ac0a906fd4
5
5
  SHA512:
6
- metadata.gz: 80193d854a2508f0a684157315f3be2d64f86da6045bed665dc66d8d74e146964c33d1fcb7fca18d971421cbf3134b1a0b4904f9ac8e649862082ff8b0c7cfc6
7
- data.tar.gz: 129464c6b469f478fba49a837674ef62d36932f4f2b480de8efe05b2e1aa053abdbd93661197e3ad3a9f3a90e7983035bb77a60baaa0e02f069761c7e47768a6
6
+ metadata.gz: 4b9e9087df014ed6cf2b10572ae24401339d08ab9c2d57b7957df65b90c49ecf51885e29a9839aee0f7236fc0fc67c108b9a88506e97994f5d3e6c40006c6eb2
7
+ data.tar.gz: 14de49fcd0fd56c4fb1c29e7fdd2ba12315ba4303e4ca0b37a9fc97d1b42c14734759a556ed67f3033cbf8a0de6bd6906d9d58ce9abc04a295cdb88a43c18cee
@@ -0,0 +1,4 @@
1
+ module IMS::LTI::Errors
2
+ class InvalidToolConsumerProfile < StandardError
3
+ end
4
+ end
@@ -2,5 +2,6 @@ module IMS::LTI
2
2
  module Errors
3
3
  require_relative 'errors/invalid_lti_config_error'
4
4
  require_relative 'errors/tool_proxy_registration_error'
5
+ require_relative 'errors/invalid_tool_consumer_profile'
5
6
  end
6
7
  end
@@ -1,6 +1,7 @@
1
1
  module IMS::LTI::Models
2
2
  class LTIModel
3
3
  LTI_VERSION_2P0 = 'LTI-2p0'
4
+ LTI_VERSION_2P0 = 'LTI-2p1'
4
5
 
5
6
  def initialize(attributes = {})
6
7
  self.attributes = attributes
@@ -1,8 +1,10 @@
1
1
  module IMS::LTI::Models
2
2
  class ServiceOwner < LTIModel
3
+ add_attribute :id, json_key:'@id'
3
4
  add_attribute :description, relation: 'IMS::LTI::Models::LocalizedText'
4
5
  add_attribute :timestamp, json_converter:'IMS::LTI::Converters::TimeJSONConverter'
5
6
  add_attribute :service_owner_name, relation: 'IMS::LTI::Models::LocalizedName'
7
+ add_attribute :support, relation:'IMS::LTI::Models::Contact'
6
8
 
7
9
  def create_service_owner_name(name, key = 'service_owner.name')
8
10
  @service_owner_name = LocalizedName.new(name, key)
@@ -0,0 +1,135 @@
1
+ module IMS::LTI::Services
2
+ class ToolProxyValidator
3
+
4
+ attr_reader :tool_proxy
5
+
6
+ def initialize(tool_proxy)
7
+ @tool_proxy = tool_proxy
8
+ end
9
+
10
+ def tool_consumer_profile
11
+ return @tool_consumer_profile if @tool_consumer_profile
12
+
13
+ connection = Faraday.new
14
+ response = connection.get(tool_proxy.tool_consumer_profile)
15
+ @tool_consumer_profile = IMS::LTI::Models::ToolConsumerProfile.new.from_json(response.body)
16
+ @tool_consumer_profile
17
+ end
18
+
19
+ def tool_consumer_profile=(tcp)
20
+ tcp = IMS::LTI::Models::ToolConsumerProfile.from_json(tcp) unless tcp.is_a?(IMS::LTI::Models::ToolConsumerProfile)
21
+ if tool_proxy.tool_consumer_profile != tcp.id
22
+ raise IMS::LTI::Errors::InvalidToolConsumerProfile, "Tool Consumer Profile @id doesn't match the Tool Proxy"
23
+ end
24
+ @tool_consumer_profile = tcp
25
+ end
26
+
27
+ def capabilities_offered
28
+ tool_consumer_profile.capabilities_offered
29
+ end
30
+
31
+ def invalid_services
32
+ services = tool_proxy.security_contract.services
33
+ services_used = services.each_with_object({}) do |s, hash|
34
+ hash[s.service.split('#').last.strip] = s.actions
35
+ hash
36
+ end
37
+ services_offered = tool_consumer_profile.services_offered.each_with_object({}) do |s, hash|
38
+ hash[s.id.split(':').last.split('#').last.strip] = s.actions
39
+ hash
40
+ end
41
+ invalid_services = services_used.each_with_object({}) do |(id, actions), hash|
42
+ if services_offered.keys.include?(id)
43
+ actions_used = normalize_strings(*services_offered[id])
44
+ actions_offered = normalize_strings(*actions)
45
+ invalid_actions = actions_offered - actions_used
46
+ hash[id] = invalid_actions unless invalid_actions.empty?
47
+ else
48
+ hash[id] = actions
49
+ end
50
+ hash
51
+ end
52
+ invalid_services
53
+ end
54
+
55
+ def invalid_message_handlers
56
+ ret_val = {}
57
+ tool_profile = tool_proxy.tool_profile
58
+ #singleton_message_handlers = tool_profile.messages
59
+ invalid_rhs = validate_resource_handlers(tool_profile.resource_handlers)
60
+ ret_val[:resource_handlers] = invalid_rhs unless invalid_rhs.empty?
61
+ invalid_singleton_message_handlers = validate_singleton_message_handlers(tool_profile.messages)
62
+ ret_val[:singleton_message_handlers] = invalid_singleton_message_handlers unless invalid_singleton_message_handlers.empty?
63
+ ret_val
64
+ end
65
+
66
+ def valid?
67
+ invalid_services.empty? && invalid_message_handlers.empty?
68
+ end
69
+
70
+
71
+ private
72
+
73
+ def normalize_strings(string, *strings)
74
+ strings.push(string)
75
+ normalized = strings.map { |s| s.upcase.strip }
76
+ normalized
77
+ end
78
+
79
+ def validate_message_handlers(message_handlers)
80
+ message_handlers.each_with_object([]) do |mh, array|
81
+ invalid_capabilities = mh.enabled_capabilities - capabilities_offered
82
+ invalid_parameters = validate_parameters(mh.parameters)
83
+ if !invalid_parameters.empty? || !invalid_capabilities.empty?
84
+ hash = {message_type: mh.message_type, }
85
+ hash[:invalid_capabilities] = invalid_capabilities unless invalid_capabilities.empty?
86
+ hash[:invalid_parameters] = invalid_parameters unless invalid_parameters.empty?
87
+ array << hash
88
+ end
89
+ array
90
+ end
91
+ end
92
+
93
+ def validate_parameters(parameters)
94
+ parameters.each_with_object([]) do |p, array|
95
+ if !p.fixed? && !capabilities_offered.include?(p.variable)
96
+ array << {name: p.name, variable: p.variable}
97
+ end
98
+ end
99
+ end
100
+
101
+ def validate_message_types(message_handlers)
102
+ message_handlers.each_with_object([]) do |mh, array|
103
+ array << mh.message_type unless capabilities_offered.include?(mh.message_type)
104
+ array
105
+ end
106
+ end
107
+
108
+ def validate_resource_handlers(resource_handlers)
109
+ resource_handlers.each_with_object([]) do |rh, array|
110
+ invalid_message_types = validate_message_types(rh.messages)
111
+ invalid_mhs = validate_message_handlers(rh.messages)
112
+ if !invalid_mhs.empty? || !invalid_message_types.empty?
113
+ hash = {
114
+ code: rh.resource_type.code,
115
+ }
116
+ hash[:messages] = invalid_mhs unless invalid_mhs.empty?
117
+ hash[:invalid_message_types] = invalid_message_types unless invalid_message_types.empty?
118
+ array << hash
119
+ end
120
+ array
121
+ end
122
+ end
123
+
124
+ def validate_singleton_message_handlers(message_handlers)
125
+ hash = {}
126
+ invalid_messages = validate_message_handlers(message_handlers)
127
+ invalid_message_types = validate_message_types(message_handlers)
128
+ hash[:messages] = invalid_messages unless invalid_messages.empty?
129
+ hash[:invalid_message_types] = invalid_message_types unless invalid_message_types.empty?
130
+ hash
131
+ end
132
+
133
+
134
+ end
135
+ end
@@ -2,5 +2,6 @@ module IMS::LTI
2
2
  module Services
3
3
  require_relative 'services/tool_proxy_registration_service'
4
4
  require_relative 'services/tool_config'
5
+ require_relative 'services/tool_proxy_validator'
5
6
  end
6
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ims-lti
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta.29
4
+ version: 2.0.0.beta.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-17 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_oauth
@@ -151,6 +151,7 @@ files:
151
151
  - lib/ims/lti/converters/time_json_converter.rb
152
152
  - lib/ims/lti/errors.rb
153
153
  - lib/ims/lti/errors/invalid_lti_config_error.rb
154
+ - lib/ims/lti/errors/invalid_tool_consumer_profile.rb
154
155
  - lib/ims/lti/errors/tool_proxy_registration_error.rb
155
156
  - lib/ims/lti/models.rb
156
157
  - lib/ims/lti/models/base_url_choice.rb
@@ -197,6 +198,7 @@ files:
197
198
  - lib/ims/lti/services.rb
198
199
  - lib/ims/lti/services/tool_config.rb
199
200
  - lib/ims/lti/services/tool_proxy_registration_service.rb
201
+ - lib/ims/lti/services/tool_proxy_validator.rb
200
202
  - lib/ims/lti/version.rb
201
203
  homepage: http://github.com/instructure/ims-lti
202
204
  licenses: