glib-web 0.4.60 → 0.4.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e115e3000243622421f51568643954470a02eb1
4
- data.tar.gz: cf697c88ba64ac3ce3731fbdb49a69f993d87f9e
3
+ metadata.gz: 187ee3620edc45227fa9735cf7fa76dcc3222e2f
4
+ data.tar.gz: 8186ad4c2983ff890edf11ec300be961d9c8687a
5
5
  SHA512:
6
- metadata.gz: 738eaed2dd23bb59903ed80a1e1c05cc06d95928a9e68ae8a24ee6137739d5d181fb40076aa1d60a3a766546d987da50271076f499d28a67ab7d2437b1f620d0
7
- data.tar.gz: 98be8ec4b19300946473005aa238bec89e1c02b0146ea0ecafb29b2dd32faf5719112562db95055813f8804da2cf893622182a10d9057ec67bde33ee8db8c54a
6
+ metadata.gz: 99ad724fbafa89f6401c08477abe1d64f3d0b0fd3c8732fa84efcef6fd24eac5a4f6e411f914b65666e25c423560d1a3dafba4ab59ffd11ab0ccf20fe020292f
7
+ data.tar.gz: 881746e07bfea3b4d200fbbed451bb6ffa8dcec1f3d530318417cf9859a9e87f2bc681f1cd7a3ee6d6fa1e461f87204f7bd2d32c2844ebe429776fdb464f751a
@@ -1,11 +1,11 @@
1
1
  module Glib
2
2
  module JsonCrawler
3
3
  class NavInitiate < ActionCrawler
4
- def initialize(http, args, controller)
4
+ def initialize(http, args, action)
5
5
  super(http)
6
-
6
+
7
7
  @http = http
8
- if (json = @http.get args['url'], controller) && (left_drawer = json['leftDrawer'])
8
+ if (json = @http.get args['url'], action) && (left_drawer = json['leftDrawer'])
9
9
  crawl left_drawer['header']&.[]('childViews')
10
10
  crawl left_drawer['rows']
11
11
  end
@@ -1,10 +1,10 @@
1
1
  module Glib
2
2
  module JsonCrawler
3
3
  class WindowsOpen < ActionCrawler
4
- def initialize http, args, controller
4
+ def initialize(http, args, action)
5
5
  @http = http
6
6
  if (url = args['url'])
7
- json = @http.get url, controller
7
+ json = @http.get url, action
8
8
 
9
9
  unless json.nil?
10
10
  crawl json['header']&.[]('childViews')
@@ -1,4 +1,3 @@
1
-
2
1
  module Glib
3
2
  module JsonCrawler
4
3
  class Http
@@ -21,30 +20,26 @@ module Glib
21
20
  @router = router
22
21
  end
23
22
 
24
- def get(url, controller)
25
- fetch(:get, url, controller)
23
+ def get(url, action, inspect_result = true)
24
+ fetch(:get, url, action, {}, inspect_result)
26
25
  end
27
26
 
28
- def post(url, controller, params)
29
- fetch(:post, url, controller, params)
27
+ def post(url, action, params)
28
+ fetch(:post, url, action, params)
30
29
  end
31
30
 
32
- def patch(url, controller, params)
33
- fetch(:patch, url, controller, params)
31
+ def patch(url, action, params)
32
+ fetch(:patch, url, action, params)
34
33
  end
35
34
 
36
- def put(url, controller, params)
37
- fetch(:put, url, controller, params)
35
+ def put(url, action, params)
36
+ fetch(:put, url, action, params)
38
37
  end
39
38
 
40
- def delete(url, controller, params = {})
41
- fetch(:delete, url, controller, {})
39
+ def delete(url, action, params = {})
40
+ fetch(:delete, url, action, {})
42
41
  end
43
42
 
44
- # def log(controller, url, response)
45
- # @router.log(controller, url, response)
46
- # end
47
-
48
43
  def controller
49
44
  @context.integration_session.controller
50
45
  end
@@ -54,7 +49,7 @@ module Glib
54
49
  end
55
50
 
56
51
  private
57
- def fetch(method, url, controller, params = {})
52
+ def fetch(method, url, action, params = {}, inspect_result = true)
58
53
  return nil if url.blank?
59
54
 
60
55
  if method == :get
@@ -82,19 +77,21 @@ module Glib
82
77
  raise
83
78
  end
84
79
  response = @context.response
85
- @router.log(controller, url, response)
86
-
87
- if (code = response.code.to_i) == 302
88
- redirect_uri = URI(response.headers['Location'])
89
- redirect_uri.query = [redirect_uri.query, 'format=json'].compact.join('&')
90
- get redirect_uri.to_s, controller
91
- else
92
- response_times << response.headers['X-Runtime'].to_f
93
- @context.assert_includes VALID_RESPONSE_CODES, code, "Expected a valid response but was [#{response.code}] #{Rack::Utils::HTTP_STATUS_CODES[response.code.to_i]}:\n#{url}"
94
- if response.media_type == 'application/json'
95
- JSON.parse(response.body)
80
+ @router.log(action, url, response)
81
+
82
+ if inspect_result
83
+ if (code = response.code.to_i) == 302
84
+ redirect_uri = URI(response.headers['Location'])
85
+ redirect_uri.query = [redirect_uri.query, 'format=json'].compact.join('&')
86
+ get redirect_uri.to_s, action
96
87
  else
97
- nil
88
+ response_times << response.headers['X-Runtime'].to_f
89
+ @context.assert_includes VALID_RESPONSE_CODES, code, "Expected a valid response but was [#{response.code}] #{Rack::Utils::HTTP_STATUS_CODES[response.code.to_i]}:\n#{url}"
90
+ if response.media_type == 'application/json'
91
+ JSON.parse(response.body)
92
+ else
93
+ nil
94
+ end
98
95
  end
99
96
  end
100
97
  end
@@ -1,84 +1,85 @@
1
-
2
- module Glib
3
- module JsonCrawler
4
- class Router
5
- # @@crawler_actions = Set.new
6
- # @@store_action = false
7
-
8
- # def self.crawler_actions
9
- # @@crawler_actions
10
- # end
11
-
12
- def log(action, url, response = nil)
13
- @logger.puts ' ' * @depth + [
14
- action,
15
- response.present? ? response.code : nil,
16
- url
17
- ].compact.join(' :: ')
18
- end
19
-
20
- def initialize(logger, store_action)
21
- # @@depth = -1
22
- # @@logger = logger
23
- # @@visitor = Glib::Json::Traversal::Visitor.new
24
- # @@store_action = store_action
25
-
26
- @depth = -1
27
- @logger = logger
28
- @visitor = Glib::Json::Traversal::Visitor.new
29
- @store_action = store_action
30
- end
31
-
32
- def step(http, args)
33
- if (controller = http.controller)
34
- Glib::JsonCrawler::Coverage.coverage_files.add(http.controller.class.instance_method(http.action_name).source_location.first)
35
- end
36
-
37
- if args.is_a?(Hash) && args['rel'] != 'nofollow'
38
- if (onClick = (args.fetch('onClick', nil) || args.fetch('onResponse', nil)))
39
- action = onClick['action']
40
- params = onClick
41
- end
42
-
43
- if action.present?
44
- @depth += 1
45
- child = case action
46
- when 'initiate_navigation'
47
- # @@crawler_actions.add([action, params['url']]) if @@store_action
48
- JsonCrawler::NavInitiate.new(http, params, action)
49
- when 'windows/open-v1', 'dialogs/open-v1', 'windows/reload-v1'
50
- unless action == 'dialogs/open-v1'
51
- # @@crawler_actions.add([action, params['url']]) if @@store_action
52
- end
53
- JsonCrawler::WindowsOpen.new(http, params, action)
54
- # when 'http/delete-v1'
55
- # JsonCrawler::ActionHttp.new(:delete, http, params, action)
56
- when 'http/post-v1'
57
- JsonCrawler::ActionHttp.new(:post, http, params, action)
58
- when 'forms/submit-v1'
59
- forms = @visitor.forms
60
- raise 'Submit action needs to be inside a form' if forms.size < 1
61
- JsonCrawler::FormsSubmit.new(http, params, action, forms.last)
62
- else
63
- unless ['http/delete-v1', 'dialogs/oauth-v1', 'windows/openWeb-v1'].include?(action)
64
- # @@crawler_actions.add([action, params['url']]) if @@store_action
65
- end
66
- self.log action, params['url']
67
- end
68
- @depth -= 1
69
- child
70
- end
71
- end
72
- end
73
-
74
- def tear_down
75
- @logger.close
76
- end
77
-
78
- def crawl_multiple(views, block)
79
- @visitor.traverse_multiple views, block
80
- end
81
-
82
- end
83
- end
84
- end
1
+ module Glib
2
+ module JsonCrawler
3
+ class Router
4
+ attr_reader :read_only_actions
5
+
6
+ def log(action, url, response = nil)
7
+ @logger.puts ' ' * @depth + [
8
+ action,
9
+ response.present? ? response.code : nil,
10
+ url
11
+ ].compact.join(' :: ')
12
+ end
13
+
14
+ def initialize(logger)
15
+ @depth = -1
16
+ @logger = logger
17
+ @visitor = Glib::Json::Traversal::Visitor.new
18
+
19
+ # @store_action = store_action
20
+
21
+ @read_only_actions = Set.new
22
+ end
23
+
24
+ def step(http, args)
25
+ if (controller = http.controller)
26
+ Glib::JsonCrawler::Coverage.coverage_files.add(controller.class.instance_method(http.action_name).source_location.first)
27
+ end
28
+
29
+ if args.is_a?(Hash) && args['rel'] != 'nofollow'
30
+ if (onClick = (args.fetch('onClick', nil) || args.fetch('onResponse', nil)))
31
+ action = onClick['action']
32
+ params = onClick
33
+ end
34
+
35
+ if action.present?
36
+ @depth += 1
37
+ child = case action
38
+ when 'initiate_navigation'
39
+ # @@crawler_actions.add([action, params['url']]) if @@store_action
40
+ @read_only_actions.add([action, params['url']])
41
+ JsonCrawler::NavInitiate.new(http, params, action)
42
+ when 'windows/open-v1', 'dialogs/open-v1', 'windows/reload-v1'
43
+ # TODO: Shouldn't dialog be crawled as well?
44
+ unless action == 'dialogs/open-v1'
45
+ # @@crawler_actions.add([action, params['url']]) if @@store_action
46
+ @read_only_actions.add([action, params['url']])
47
+ end
48
+ JsonCrawler::WindowsOpen.new(http, params, action)
49
+ when 'http/post-v1'
50
+ JsonCrawler::ActionHttp.new(:post, http, params, action)
51
+ when 'forms/submit-v1'
52
+ forms = @visitor.forms
53
+ raise 'Submit action needs to be inside a form' if forms.size < 1
54
+ JsonCrawler::FormsSubmit.new(http, params, action, forms.last)
55
+ else
56
+ unless ['http/delete-v1', 'dialogs/oauth-v1', 'windows/openWeb-v1'].include?(action)
57
+ # @@crawler_actions.add([action, params['url']]) if @@store_action
58
+ @read_only_actions.add([action, params['url']])
59
+ end
60
+ self.log action, params['url']
61
+ end
62
+ @depth -= 1
63
+ child
64
+ end
65
+ end
66
+ end
67
+
68
+ def follow(http, target_router)
69
+ @depth += 1
70
+ target_router.read_only_actions.each do |crawler_action|
71
+ action, url = crawler_action
72
+ http.get url, action, false
73
+ end
74
+ end
75
+
76
+ def tear_down
77
+ @logger.close
78
+ end
79
+
80
+ def crawl_multiple(views, block)
81
+ @visitor.traverse_multiple views, block
82
+ end
83
+ end
84
+ end
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.60
4
+ version: 0.4.61
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''