que-web 0.8.0 → 0.9.0

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
- SHA256:
3
- metadata.gz: 47ad5fd3031d35ffde2d864982d7f7d044b3fd2bc193f8922a9bad7ab71784a6
4
- data.tar.gz: eca71d27a53c880ba3b1d7fd389556d675badf38b5e91631dff93e1f17eb7652
2
+ SHA1:
3
+ metadata.gz: e450eca7ca5dbad2f7fe76dc6bfbf49e9f669fb3
4
+ data.tar.gz: 9d469004ae8c91444d63689b1b39fafc5be5ab4b
5
5
  SHA512:
6
- metadata.gz: d5e19332be846121014c41f85fb5d86bb5bb672745f136e2e9e5bfd75c36a5c39bbfe68711f8b51e8c7db578adfd1106f4a415acf76f5387e7f4421de4ead8b5
7
- data.tar.gz: c0511bdd77dfad2284ee0781b52e51392df33dd62856ccd99b27beb09360430abb6df9ce92ea5a2e44df5477b1d2b2032bcb6d8a3f346b3ddb7e75d91719c350
6
+ metadata.gz: 862a3020cd60dde9f89e95d67a4ec4a9ce572c751852a12fd53ed5d87be8d5d3ec2d136d83a673ea8461214ff4ff3d5de89e80ba6edc8f976dbb9949e15e65a0
7
+ data.tar.gz: 3c70089ccd11c6af4da114257336655528f7dd27913754e6d6a7ce731f8231c342cfdf5f366eadc0433a92751a5fb15126aa3a5b466970952869901bd443612a
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1
3
+ - 2.4
4
+ - 2.5
5
+ - 2.6
6
6
  - jruby
7
7
  notifications:
8
8
  email: false
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
1
  ### Unreleased
2
+ #### Added:
3
+ - Display real job class when wrapped by ActiveJob
4
+ - Updated foundation CSS to latest 5.x version
5
+ - Removed erubis gem dependency
6
+
7
+ #### Fixed:
8
+ - Fixed minitest deprecation warnings
2
9
 
3
10
  ### 0.8 - 2018-09-21
4
11
 
data/README.md CHANGED
@@ -43,18 +43,6 @@ require "que/web"
43
43
  mount Que::Web => "/que"
44
44
  ```
45
45
 
46
- #### Rails 5.0
47
-
48
- You must use the master branch of Sinatra for `que-web`.
49
- In your gemfile:
50
-
51
- ```
52
- gem 'que-web'
53
- gem 'sinatra', git: 'https://github.com/sinatra/sinatra'
54
- ```
55
-
56
- See https://github.com/sinatra/sinatra/issues/1071
57
-
58
46
  ### Authentication
59
47
 
60
48
  #### Devise
data/docker/Gemfile.lock CHANGED
@@ -2,24 +2,24 @@ GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
4
  erubis (2.7.0)
5
- mustermann (1.0.1)
5
+ mustermann (1.0.3)
6
6
  pg (1.0.0)
7
- puma (3.11.2)
7
+ puma (3.12.3)
8
8
  que (0.14.2)
9
9
  que-web (0.7.0)
10
10
  erubis
11
11
  que (~> 0.8)
12
12
  sinatra
13
- rack (2.0.4)
14
- rack-protection (2.0.0)
13
+ rack (2.0.8)
14
+ rack-protection (2.0.7)
15
15
  rack
16
16
  sequel (5.5.0)
17
- sinatra (2.0.0)
17
+ sinatra (2.0.7)
18
18
  mustermann (~> 1.0)
19
19
  rack (~> 2.0)
20
- rack-protection (= 2.0.0)
20
+ rack-protection (= 2.0.7)
21
21
  tilt (~> 2.0)
22
- tilt (2.0.8)
22
+ tilt (2.0.10)
23
23
 
24
24
  PLATFORMS
25
25
  ruby
@@ -1,28 +1,28 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- que-web (0.7.0)
5
- erubis
6
- que (~> 0.8)
4
+ que-web (0.8.0)
5
+ que (~> 1.0.0.beta3)
7
6
  sinatra
8
7
 
9
8
  GEM
10
9
  remote: https://rubygems.org/
11
10
  specs:
12
- erubis (2.7.0)
13
- mustermann (1.0.1)
14
- pg (1.0.0)
15
- que (0.14.2)
16
- rack (2.0.4)
17
- rack-protection (2.0.0)
11
+ mustermann (1.1.1)
12
+ ruby2_keywords (~> 0.0.1)
13
+ pg (1.2.3)
14
+ que (1.0.0.beta4)
15
+ rack (2.2.2)
16
+ rack-protection (2.0.8.1)
18
17
  rack
19
- sequel (5.5.0)
20
- sinatra (2.0.0)
18
+ ruby2_keywords (0.0.2)
19
+ sequel (5.30.0)
20
+ sinatra (2.0.8.1)
21
21
  mustermann (~> 1.0)
22
22
  rack (~> 2.0)
23
- rack-protection (= 2.0.0)
23
+ rack-protection (= 2.0.8.1)
24
24
  tilt (~> 2.0)
25
- tilt (2.0.8)
25
+ tilt (2.0.10)
26
26
 
27
27
  PLATFORMS
28
28
  ruby
@@ -33,4 +33,4 @@ DEPENDENCIES
33
33
  sequel
34
34
 
35
35
  BUNDLED WITH
36
- 1.15.3
36
+ 2.1.4
@@ -7,9 +7,8 @@ require 'securerandom'
7
7
 
8
8
  Que.logger = Logger.new(STDOUT)
9
9
  Que.logger.level = Logger::INFO
10
- Que.connection = Sequel.connect "postgres://localhost/quewebtest", max_connections: Que.worker_count + 1
11
- Que.migrate!
12
- Que.mode = :async
10
+ Que.connection = Sequel.connect("postgres://localhost/quewebtest", max_connections: 1)
11
+ Que.migrate!(version: 4)
13
12
  $stdout.sync = true
14
13
 
15
14
  class FailJob < Que::Job
@@ -31,4 +30,3 @@ class SlowJob < Que::Job
31
30
  sleep 15
32
31
  end
33
32
  end
34
-
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  map '/xss' do
24
24
  run lambda { |env|
25
- FailJob.enqueue '<script>alert("xss")</script>', {name: '<script>alert("xss")', age: 20, numbers: [10]*50}
25
+ FailJob.enqueue "<script>alert('xss')</script>", {name: "<script>alert('xss')", age: 20, numbers: [10]*50}
26
26
  [200, {}, ['Failing job queued']]
27
27
  }
28
28
  end
@@ -41,7 +41,6 @@ map '/slow' do
41
41
  }
42
42
  end
43
43
 
44
-
45
44
  map '/delayslow' do
46
45
  run lambda { |env|
47
46
  SlowJob.enqueue 'arg1', {name: 'delayslow', age: 20}, run_at: Time.now + 10
@@ -52,4 +51,3 @@ end
52
51
  run lambda { |env|
53
52
  [200, {}, ['Hello']]
54
53
  }
55
-
data/lib/que/web.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "sinatra/base"
2
- require "erubis"
2
+ require "cgi"
3
3
 
4
4
  module Que
5
5
  class Web < Sinatra::Base
@@ -164,7 +164,7 @@ module Que
164
164
  end
165
165
 
166
166
  def search_param
167
- sanitised = (params['search'] || '').gsub(/[^0-9a-z:]i/, '')
167
+ sanitised = (params['search'] || '').gsub(/[^0-9a-z:]/i, '')
168
168
  return if sanitised.empty?
169
169
  sanitised
170
170
  end
@@ -206,6 +206,13 @@ module Que
206
206
  hash = session[FLASH_KEY] ||= {}
207
207
  hash[level] = val
208
208
  end
209
+
210
+ def html_escape(text)
211
+ return if text.nil?
212
+
213
+ CGI.escape_html(text)
214
+ end
215
+ alias h html_escape
209
216
  end
210
217
  helpers Helpers
211
218
  end
@@ -1,3 +1,5 @@
1
+ require "json"
2
+
1
3
  Dir[File.expand_path('../viewmodels/*.rb', __FILE__)].each {|f| require f}
2
4
  module Que::Web::Viewmodels
3
5
  end
@@ -13,5 +13,14 @@ module Que::Web::Viewmodels
13
13
  def past_due?(relative_to = Time.now)
14
14
  run_at < relative_to
15
15
  end
16
+
17
+ def humanized_job_class
18
+ case job_class
19
+ when "ActiveJob::QueueAdapters::QueAdapter::JobWrapper"
20
+ args.first[:job_class]
21
+ else
22
+ job_class
23
+ end
24
+ end
16
25
  end
17
26
  end
data/que-web.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "que-web"
7
- spec.version = "0.8.0"
7
+ spec.version = "0.9.0"
8
8
  spec.authors = ["Jason Staten", "Bruno Porto"]
9
9
  spec.email = ["jstaten07@gmail.com", "brunotporto@gmail.com"]
10
10
  spec.summary = %q{A web interface for the que queue}
@@ -19,9 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "que", "~> 1.0.0.beta3"
21
21
  spec.add_dependency "sinatra"
22
- spec.add_dependency "erubis"
23
22
 
24
- spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "minitest", "~> 5.4"
23
+ spec.add_development_dependency "bundler", ">= 1.6"
24
+ spec.add_development_dependency "rake", ">= 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.6"
27
26
  end
data/spec/pager_spec.rb CHANGED
@@ -5,49 +5,49 @@ describe Que::Web::Pager do
5
5
  subject { Que::Web::Pager.new(4, 10, 105) }
6
6
 
7
7
  it "provides passed values" do
8
- subject.current_page.must_equal 4
9
- subject.page_size.must_equal 10
10
- subject.total.must_equal 105
8
+ _(subject.current_page).must_equal 4
9
+ _(subject.page_size).must_equal 10
10
+ _(subject.total).must_equal 105
11
11
  end
12
12
 
13
13
  it "provides a page count" do
14
- subject.page_count.must_equal 11
14
+ _(subject.page_count).must_equal 11
15
15
  end
16
16
 
17
17
  it "defaults to page count of 1 if total is 0" do
18
18
  pager = Que::Web::Pager.new(4, 10, 0)
19
- pager.page_count.must_equal 1
19
+ _(pager.page_count).must_equal 1
20
20
  end
21
21
 
22
22
  it "increments next page if it exists" do
23
- subject.next_page.must_equal 5
23
+ _(subject.next_page).must_equal 5
24
24
  end
25
25
 
26
26
  it "provides nil next page if on last page" do
27
27
  pager = Que::Web::Pager.new(11, 10, 105)
28
- pager.next_page.must_be_nil
28
+ _(pager.next_page).must_be_nil
29
29
  end
30
30
 
31
31
  it "decrements prev page if it exists" do
32
- subject.prev_page.must_equal 3
32
+ _(subject.prev_page).must_equal 3
33
33
  end
34
34
 
35
35
  it "provides nil prev page if on first page" do
36
36
  pager = Que::Web::Pager.new(1, 10, 105)
37
- pager.prev_page.must_be_nil
37
+ _(pager.prev_page).must_be_nil
38
38
  end
39
39
 
40
40
  it "determines offset" do
41
- subject.offset.must_equal 30
41
+ _(subject.offset).must_equal 30
42
42
  end
43
43
 
44
44
  it "sets page_no less than 1 to 1 for current page" do
45
45
  pager = Que::Web::Pager.new(-3, 10, 105)
46
- pager.current_page.must_equal 1
46
+ _(pager.current_page).must_equal 1
47
47
  end
48
48
 
49
49
  it "provides range centering current page" do
50
50
  pager = Que::Web::Pager.new(-3, 10, 105)
51
- pager.current_page.must_equal 1
51
+ _(pager.current_page).must_equal 1
52
52
  end
53
53
  end
@@ -0,0 +1,63 @@
1
+ require "spec_helper"
2
+ require "que/web"
3
+
4
+ describe Que::Web::Helpers do
5
+ subject { Que::Web::Helpers.new(4, 10, 105) }
6
+
7
+ def subject_with_attributes(**attributes)
8
+ Class.new do
9
+ include Que::Web::Helpers
10
+
11
+ attributes.each { |attr, value| define_method(attr) { value } }
12
+ end.new
13
+ end
14
+
15
+ describe '#search' do
16
+ it 'returns a wildcard search with a search_param' do
17
+ _(subject_with_attributes(search_param: 'foobar').search).must_equal '%foobar%'
18
+ end
19
+
20
+ it 'returns a wildcard search without a search_param' do
21
+ _(subject_with_attributes(search_param: nil).search).must_equal '%'
22
+ end
23
+ end
24
+
25
+ describe '#search_param' do
26
+ def search_param_for(search)
27
+ subject_with_attributes(params: { 'search' => search }).search_param
28
+ end
29
+
30
+ it 'is nil if the search_param is not present' do
31
+ assert_nil(search_param_for(nil))
32
+ end
33
+
34
+ it 'is nil if the search_param is present but empty' do
35
+ assert_nil(search_param_for(''))
36
+ end
37
+
38
+ it 'is nil if the search_param is empty after sanitisation' do
39
+ assert_nil(search_param_for('! ?'))
40
+ end
41
+
42
+ it 'preserves a valid Ruby class name' do
43
+ _(search_param_for("Namespaced::Class")).must_equal 'Namespaced::Class'
44
+ end
45
+
46
+ it 'sanitises the passed search' do
47
+ _(search_param_for("(Foo) / !Bar! --Baz")).must_equal 'FooBarBaz'
48
+ end
49
+
50
+ it 'preserves A-Z, a-z, 0-9 and : in the search param' do
51
+ search = (('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a).join + ':'
52
+ _(search_param_for(search)).must_equal search
53
+ end
54
+ end
55
+
56
+ describe '#escape_html' do
57
+ it 'prevents XSS' do
58
+ _(subject_with_attributes.h("<sript>alert('XSS')</script>")).must_equal(
59
+ "&lt;sript&gt;alert(&#39;XSS&#39;)&lt;/script&gt;"
60
+ )
61
+ end
62
+ end
63
+ end
@@ -12,6 +12,6 @@ describe Que::Web::Viewmodels::Dashboard do
12
12
  let(:subject) { Que::Web::Viewmodels::Dashboard.new(dashboard_stats) }
13
13
 
14
14
  it 'passes through values' do
15
- subject.scheduled.must_equal 2
15
+ _(subject.scheduled).must_equal 2
16
16
  end
17
17
  end
@@ -15,16 +15,15 @@ describe Que::Web::Viewmodels::JobList do
15
15
  let(:subject) { Que::Web::Viewmodels::JobList.new([job], pager) }
16
16
 
17
17
  it "maps jobs" do
18
- subject.page_jobs.length.must_equal 1
19
- subject.page_jobs.first.queue.must_equal "foo"
18
+ _(subject.page_jobs.length).must_equal 1
19
+ _(subject.page_jobs.first.queue).must_equal "foo"
20
20
  end
21
21
 
22
22
  it "exposes pager" do
23
- subject.pager.must_equal pager
23
+ _(subject.pager).must_equal pager
24
24
  end
25
25
 
26
26
  it "maps total from pager" do
27
- subject.total.must_equal pager.total
27
+ _(subject.total).must_equal pager.total
28
28
  end
29
-
30
29
  end
@@ -14,18 +14,30 @@ describe Que::Web::Viewmodels::Job do
14
14
  let(:subject) { Que::Web::Viewmodels::Job.new(source_job) }
15
15
 
16
16
  it 'maps fields from source' do
17
- subject.priority.must_equal source_job[:priority]
18
- subject.queue.must_equal source_job[:queue]
17
+ _(subject.priority).must_equal source_job[:priority]
18
+ _(subject.queue).must_equal source_job[:queue]
19
+ end
20
+
21
+ describe 'humanized_job_class' do
22
+ it 'returns job class on unknown wrapper' do
23
+ _(subject.humanized_job_class).must_equal "SuccessJob"
24
+ end
25
+
26
+ it 'returns wrapped job class for Active Job' do
27
+ source = source_job.merge(job_class: "ActiveJob::QueueAdapters::QueAdapter::JobWrapper", args: [job_class: "MyJob"])
28
+ job = Que::Web::Viewmodels::Job.new(source)
29
+ _(job.humanized_job_class).must_equal "MyJob"
30
+ end
19
31
  end
20
32
 
21
33
  describe 'schedule' do
22
34
  it 'is past due when run_at is behind' do
23
- subject.must_be :past_due?
35
+ _(subject).must_be :past_due?
24
36
  end
25
37
 
26
38
  it 'is not past due when run_at is ahead of now' do
27
39
  subject.run_at = Time.now + 3600
28
- subject.wont_be :past_due?
40
+ _(subject).wont_be :past_due?
29
41
  end
30
42
  end
31
43
  end