redis_monitor 0.0.5 → 0.0.6
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.
- data/.travis.yml +8 -0
- data/README.md +7 -2
- data/lib/controllers/base_controller.rb +4 -0
- data/lib/controllers/content_controller.rb +13 -2
- data/lib/helpers/base_helper.rb +4 -0
- data/lib/helpers/layouts_helper.rb +3 -0
- data/lib/helpers/pagination_helper.rb +5 -0
- data/lib/modules/backend.rb +5 -1
- data/lib/modules/controllers.rb +1 -0
- data/lib/modules/helpers.rb +1 -0
- data/lib/modules/router.rb +1 -0
- data/lib/modules/security/authentication.rb +29 -0
- data/lib/modules/security/authorization.rb +18 -0
- data/lib/modules/version.rb +1 -1
- data/lib/redis_monitor.rb +5 -0
- data/lib/server/command_line_parser.rb +15 -3
- data/lib/server/server.rb +5 -0
- data/lib/views/content/search.haml +11 -0
- data/redis_monitor.gemspec +3 -1
- data/spec/controllers/base_controller_spec.rb +7 -9
- data/spec/controllers/content_controller_spec.rb +26 -9
- data/spec/controllers/info_controller_spec.rb +6 -8
- data/spec/controllers/performance_controller_spec.rb +6 -8
- data/spec/modules/backend_spec.rb +17 -9
- data/spec/modules/security/authentication_spec.rb +48 -0
- data/spec/modules/security/authorization_spec.rb +17 -0
- data/spec/server/command_line_parser_spec.rb +16 -0
- data/spec/spec_helper.rb +4 -1
- metadata +68 -12
- checksums.yaml +0 -7
    
        data/.travis.yml
    ADDED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            # RedisMonitor
         | 
| 2 | 
            +
            [](https://travis-ci.org/javiyu/redis_monitor)
         | 
| 2 3 |  | 
| 3 4 | 
             
            ## Installation
         | 
| 4 5 |  | 
| @@ -16,10 +17,14 @@ Or install it yourself as: | |
| 16 17 |  | 
| 17 18 | 
             
            ## Usage
         | 
| 18 19 |  | 
| 19 | 
            -
                $ redis_monitor --http-port http_port --host host --port port
         | 
| 20 | 
            +
                $ redis_monitor --http-port http_port --host redis-host --port redis-port
         | 
| 20 21 |  | 
| 21 22 | 
             
            Then browse http://localhost:http_port
         | 
| 22 23 |  | 
| 24 | 
            +
            --editable or --not-editable can be use to indicate if the user should be able to edit the database content.
         | 
| 25 | 
            +
            --credentials user:password if only users with credentials can access the application.
         | 
| 26 | 
            +
             | 
| 27 | 
            +
             | 
| 23 28 | 
             
            For more information about the parameters:
         | 
| 24 29 |  | 
| 25 30 | 
             
                $ redis_monitor --help
         | 
| @@ -32,6 +37,6 @@ For more information about the parameters: | |
| 32 37 | 
             
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 33 38 | 
             
            5. Create new Pull Request
         | 
| 34 39 |  | 
| 35 | 
            -
            Please write meaningful test,  | 
| 40 | 
            +
            Please write meaningful test, if you need to execute them:
         | 
| 36 41 |  | 
| 37 42 | 
             
                $ rspec spec
         | 
| @@ -11,9 +11,20 @@ module RedisMonitor | |
| 11 11 | 
             
                  end
         | 
| 12 12 |  | 
| 13 13 | 
             
                  def search(params = {})
         | 
| 14 | 
            -
                    results = Backend.search(params[:key])
         | 
| 15 | 
            -
                    haml 'content/search'.to_sym, layout: main_layout, locals: {results: results, section: SECTION}
         | 
| 14 | 
            +
                    results = Backend.search(params[:key]).paginate(:page => params[:page], :per_page => 20)
         | 
| 15 | 
            +
                    haml 'content/search'.to_sym, layout: main_layout, locals: {results: results, section: SECTION, object: self}
         | 
| 16 16 | 
             
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def delete(params = {})
         | 
| 19 | 
            +
                    Backend.del(params[:key])
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    if http_referer
         | 
| 22 | 
            +
                      context.redirect http_referer
         | 
| 23 | 
            +
                    else
         | 
| 24 | 
            +
                      redirect '/content/search'
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 17 28 | 
             
                end
         | 
| 18 29 | 
             
              end
         | 
| 19 30 | 
             
            end
         | 
    
        data/lib/helpers/base_helper.rb
    CHANGED
    
    
    
        data/lib/modules/backend.rb
    CHANGED
    
    | @@ -7,7 +7,7 @@ module RedisMonitor | |
| 7 7 | 
             
              class Backend
         | 
| 8 8 | 
             
                extend SingleForwardable
         | 
| 9 9 |  | 
| 10 | 
            -
                def_delegators :redis, :get, :set, : | 
| 10 | 
            +
                def_delegators :redis, :get, :set, :info, :keys, :dbsize, :monitor
         | 
| 11 11 |  | 
| 12 12 | 
             
                def self.config(arguments)
         | 
| 13 13 | 
             
                  @@host = arguments[:redis_host]
         | 
| @@ -33,5 +33,9 @@ module RedisMonitor | |
| 33 33 | 
             
                def self.search(key)
         | 
| 34 34 | 
             
                  keys(key).map{|found| {key: found, value: get(found)} }
         | 
| 35 35 | 
             
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def self.del(key)
         | 
| 38 | 
            +
                  redis.del(key) if Authorization.authorized_for?(:remove_content)
         | 
| 39 | 
            +
                end
         | 
| 36 40 | 
             
              end
         | 
| 37 41 | 
             
            end
         | 
    
        data/lib/modules/controllers.rb
    CHANGED
    
    
    
        data/lib/modules/helpers.rb
    CHANGED
    
    
    
        data/lib/modules/router.rb
    CHANGED
    
    | @@ -11,6 +11,7 @@ module RedisMonitor | |
| 11 11 |  | 
| 12 12 | 
             
                  server.get('/content'){ ContentController.new(context: self).execute(:index, params) }
         | 
| 13 13 | 
             
                  server.get('/content/search'){ ContentController.new(context: self).execute(:search, params) }
         | 
| 14 | 
            +
                  server.post('/content/delete'){ ContentController.new(context: self).execute(:delete, params) }
         | 
| 14 15 |  | 
| 15 16 | 
             
                  server.get('/performance'){ redirect '/performance/warning' }
         | 
| 16 17 | 
             
                  server.get('/performance/warning'){ PerformanceController.new(context: self).execute(:warning, params) }
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            module RedisMonitor
         | 
| 2 | 
            +
              module Authentication
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def self.config(server, credentials)
         | 
| 5 | 
            +
                  @@credentials = credentials
         | 
| 6 | 
            +
                  @@server = server
         | 
| 7 | 
            +
                  inject_authentication
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def self.inject_authentication
         | 
| 11 | 
            +
                  if authentication_required?
         | 
| 12 | 
            +
                    @@server.class_eval do
         | 
| 13 | 
            +
                      use Rack::Auth::Basic, 'Restricted Area' do |username, password|
         | 
| 14 | 
            +
                        username == Authentication.credentials[:user] and password == Authentication.credentials[:password]
         | 
| 15 | 
            +
                      end
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
             | 
| 21 | 
            +
                def self.authentication_required?
         | 
| 22 | 
            +
                  !!credentials
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def self.credentials
         | 
| 26 | 
            +
                  @@credentials
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
            end
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            module RedisMonitor
         | 
| 2 | 
            +
              class Authorization
         | 
| 3 | 
            +
                DEFAULTS = {remove_content: true}
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def self.config(opts = {})
         | 
| 6 | 
            +
                  opts = {} unless opts
         | 
| 7 | 
            +
                  @@permissions = DEFAULTS.merge(opts)
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def self.permissions
         | 
| 11 | 
            +
                  @@permissions
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def self.authorized_for?(action)
         | 
| 15 | 
            +
                  !!permissions[action]
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
    
        data/lib/modules/version.rb
    CHANGED
    
    
    
        data/lib/redis_monitor.rb
    CHANGED
    
    | @@ -1,11 +1,16 @@ | |
| 1 1 | 
             
            require 'server/command_line_parser'
         | 
| 2 2 | 
             
            require 'server/server'
         | 
| 3 | 
            +
            require 'modules/security/authorization'
         | 
| 4 | 
            +
            require 'modules/security/authentication'
         | 
| 3 5 |  | 
| 4 6 | 
             
            module RedisMonitor
         | 
| 5 7 | 
             
              def self.run
         | 
| 6 8 | 
             
                arguments = CommandLineParser.parse(ARGV.dup)
         | 
| 7 9 | 
             
                Backend.config(arguments)
         | 
| 8 10 | 
             
                Server.config(arguments)
         | 
| 11 | 
            +
                Authorization.config(arguments[:permissions])
         | 
| 12 | 
            +
                Authentication.config(Server, arguments[:credentials])
         | 
| 13 | 
            +
             | 
| 9 14 | 
             
                Server.run!
         | 
| 10 15 | 
             
              end
         | 
| 11 16 | 
             
            end
         | 
| @@ -3,7 +3,7 @@ require 'optparse' | |
| 3 3 | 
             
            module RedisMonitor
         | 
| 4 4 | 
             
              class CommandLineParser
         | 
| 5 5 | 
             
                DEFAULTS = {
         | 
| 6 | 
            -
                  http_server: ' | 
| 6 | 
            +
                  http_server: 'webrick',
         | 
| 7 7 | 
             
                  http_port: 6369,
         | 
| 8 8 | 
             
                  redis_host: 'localhost',
         | 
| 9 9 | 
             
                  redis_port: 6379,
         | 
| @@ -19,12 +19,24 @@ module RedisMonitor | |
| 19 19 | 
             
                    op.on('--http-port port',  'specify http port (default is 6369)') do |val|
         | 
| 20 20 | 
             
                      arguments[:http_port] = val.to_i
         | 
| 21 21 | 
             
                    end
         | 
| 22 | 
            -
                    op.on('--host host',  'specify redis host (default is localhost)') do |val|
         | 
| 22 | 
            +
                    op.on('--host redis-host',  'specify redis host (default is localhost)') do |val|
         | 
| 23 23 | 
             
                      arguments[:redis_host] = val
         | 
| 24 24 | 
             
                    end
         | 
| 25 | 
            -
                    op.on('--port port',  'specify redis port (default is 6379)') do |val|
         | 
| 25 | 
            +
                    op.on('--port redis-port',  'specify redis port (default is 6379)') do |val|
         | 
| 26 26 | 
             
                      arguments[:redis_port] = val.to_i
         | 
| 27 27 | 
             
                    end
         | 
| 28 | 
            +
                    op.on('--editable',  'the content will be editable (default is editable)') do |val|
         | 
| 29 | 
            +
                      arguments[:permissions] ||= {}
         | 
| 30 | 
            +
                      arguments[:permissions][:remove_content] = true
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
                    op.on('--not-editable',  'the content will be not editable (default is editable)') do |val|
         | 
| 33 | 
            +
                      arguments[:permissions] ||= {}
         | 
| 34 | 
            +
                      arguments[:permissions][:remove_content] = false
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                    op.on('--credentials credentials',  'access only with credentials (format user:password)') do |val|
         | 
| 37 | 
            +
                      user, password = val.to_s.split(':')
         | 
| 38 | 
            +
                      arguments[:credentials] = {user: user, password: password}
         | 
| 39 | 
            +
                    end
         | 
| 28 40 | 
             
                  end
         | 
| 29 41 | 
             
                  parser.parse!(argv)
         | 
| 30 42 |  | 
    
        data/lib/server/server.rb
    CHANGED
    
    | @@ -1,11 +1,16 @@ | |
| 1 1 | 
             
            require 'sinatra'
         | 
| 2 2 | 
             
            require 'haml'
         | 
| 3 3 | 
             
            require 'modules/router'
         | 
| 4 | 
            +
            require 'modules/security/authorization'
         | 
| 5 | 
            +
            require 'will_paginate/view_helpers/sinatra'
         | 
| 6 | 
            +
            require 'will_paginate-bootstrap'
         | 
| 4 7 |  | 
| 5 8 | 
             
            module RedisMonitor
         | 
| 6 9 | 
             
              class Server < Sinatra::Base
         | 
| 7 10 | 
             
                include RedisMonitor::Router
         | 
| 8 11 | 
             
                include RedisMonitor::Helpers::LayoutsHelper
         | 
| 12 | 
            +
                include WillPaginate::Sinatra::Helpers
         | 
| 13 | 
            +
                include PaginationHelper
         | 
| 9 14 |  | 
| 10 15 | 
             
                set :public_folder, File.dirname(__FILE__) + '/../static'
         | 
| 11 16 | 
             
                set :views, File.dirname(__FILE__) + '/../views'
         | 
| @@ -7,6 +7,9 @@ | |
| 7 7 | 
             
                    Key
         | 
| 8 8 | 
             
                  %th
         | 
| 9 9 | 
             
                    Value
         | 
| 10 | 
            +
                  - if authorized_for?(:remove_content)
         | 
| 11 | 
            +
                    %th
         | 
| 12 | 
            +
                      Actions
         | 
| 10 13 |  | 
| 11 14 | 
             
              %tbody
         | 
| 12 15 | 
             
                - results.each do |result|
         | 
| @@ -15,3 +18,11 @@ | |
| 15 18 | 
             
                      = result[:key]
         | 
| 16 19 | 
             
                    %td
         | 
| 17 20 | 
             
                      = result[:value]
         | 
| 21 | 
            +
                    - if authorized_for?(:remove_content)
         | 
| 22 | 
            +
                      %td
         | 
| 23 | 
            +
                        %form{action: '/content/delete', method: 'post'}
         | 
| 24 | 
            +
                          %input{type: 'hidden', name: 'key', value: result[:key]}
         | 
| 25 | 
            +
                          %button.btn.btn-danger
         | 
| 26 | 
            +
                            Delete
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            = bootstrap_paginate results
         | 
    
        data/redis_monitor.gemspec
    CHANGED
    
    | @@ -19,9 +19,11 @@ Gem::Specification.new do |spec| | |
| 19 19 | 
             
              spec.require_paths = %w(lib)
         | 
| 20 20 |  | 
| 21 21 | 
             
              spec.add_runtime_dependency 'sinatra', '~> 1.4'
         | 
| 22 | 
            -
              spec.add_runtime_dependency ' | 
| 22 | 
            +
              spec.add_runtime_dependency 'webrick'
         | 
| 23 23 | 
             
              spec.add_runtime_dependency 'redis', '~> 3.0'
         | 
| 24 24 | 
             
              spec.add_runtime_dependency 'haml', '~> 4.0'
         | 
| 25 | 
            +
              spec.add_runtime_dependency 'will_paginate', '~> 3.0'
         | 
| 26 | 
            +
              spec.add_runtime_dependency 'will_paginate-bootstrap'
         | 
| 25 27 |  | 
| 26 28 | 
             
              spec.add_development_dependency 'bundler', '~> 1.3'
         | 
| 27 29 | 
             
              spec.add_development_dependency 'rake'
         | 
| @@ -1,16 +1,14 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe BaseController do
         | 
| 4 | 
            -
               | 
| 5 | 
            -
             | 
| 6 | 
            -
                @controller = BaseController.new(context: @context)
         | 
| 7 | 
            -
              end
         | 
| 4 | 
            +
              let(:context){ double() }
         | 
| 5 | 
            +
              let(:controller){ BaseController.new(context: context) }
         | 
| 8 6 |  | 
| 9 7 | 
             
              describe 'execute method' do
         | 
| 10 8 | 
             
                it 'should not raise error if the action executed raised RedisNotAvailable' do
         | 
| 11 | 
            -
                   | 
| 12 | 
            -
                   | 
| 13 | 
            -
                  expect{  | 
| 9 | 
            +
                  controller.stub(:action) { raise RedisNotAvailable }
         | 
| 10 | 
            +
                  controller.should_receive(:redis_not_available)
         | 
| 11 | 
            +
                  expect{ controller.execute(:action) }.not_to raise_error
         | 
| 14 12 | 
             
                end
         | 
| 15 13 | 
             
              end
         | 
| 16 14 |  | 
| @@ -18,8 +16,8 @@ describe BaseController do | |
| 18 16 | 
             
                it 'should render redis not available error page' do
         | 
| 19 17 | 
             
                  Backend.stub(:host)
         | 
| 20 18 | 
             
                  Backend.stub(:port)
         | 
| 21 | 
            -
                   | 
| 22 | 
            -
                   | 
| 19 | 
            +
                  context.should_receive(:haml).with('errors/redis_not_available'.to_sym, anything)
         | 
| 20 | 
            +
                  controller.redis_not_available
         | 
| 23 21 | 
             
                end
         | 
| 24 22 | 
             
              end
         | 
| 25 23 | 
             
            end
         | 
| @@ -1,23 +1,40 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe ContentController do
         | 
| 4 | 
            -
               | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
              end
         | 
| 4 | 
            +
              let(:context){ double() }
         | 
| 5 | 
            +
              let(:controller){ ContentController.new(context: context) }
         | 
| 6 | 
            +
              let(:search_results){ double(paginate: []) }
         | 
| 8 7 |  | 
| 9 8 | 
             
              describe 'index action' do
         | 
| 10 9 | 
             
                it 'should render index template' do
         | 
| 11 | 
            -
                   | 
| 12 | 
            -
                   | 
| 10 | 
            +
                  context.should_receive(:haml).with('content/index'.to_sym, anything)
         | 
| 11 | 
            +
                  controller.index
         | 
| 13 12 | 
             
                end
         | 
| 14 13 | 
             
              end
         | 
| 15 14 |  | 
| 16 15 | 
             
              describe 'search action' do
         | 
| 17 16 | 
             
                it 'should render search template' do
         | 
| 18 | 
            -
                  Backend.stub(:search){  | 
| 19 | 
            -
                   | 
| 20 | 
            -
                   | 
| 17 | 
            +
                  Backend.stub(:search){ search_results }
         | 
| 18 | 
            +
                  context.should_receive(:haml).with('content/search'.to_sym, anything)
         | 
| 19 | 
            +
                  controller.search
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              describe 'delete action' do
         | 
| 24 | 
            +
                before :each do
         | 
| 25 | 
            +
                  Backend.stub(:del)
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                it 'should redirect to the referer if exists' do
         | 
| 29 | 
            +
                  controller.stub(:http_referer){ '/referer' }
         | 
| 30 | 
            +
                  context.should_receive(:redirect).with('/referer')
         | 
| 31 | 
            +
                  controller.delete
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                it 'should redirect to search page if referer does not exists' do
         | 
| 35 | 
            +
                  controller.stub(:http_referer){ nil }
         | 
| 36 | 
            +
                  context.should_receive(:redirect).with('/content/search')
         | 
| 37 | 
            +
                  controller.delete
         | 
| 21 38 | 
             
                end
         | 
| 22 39 | 
             
              end
         | 
| 23 40 | 
             
            end
         | 
| @@ -1,10 +1,8 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe InfoController do
         | 
| 4 | 
            -
               | 
| 5 | 
            -
             | 
| 6 | 
            -
                @controller = InfoController.new(context: @context)
         | 
| 7 | 
            -
              end
         | 
| 4 | 
            +
              let(:context){ double() }
         | 
| 5 | 
            +
              let(:controller){ InfoController.new(context: context) }
         | 
| 8 6 |  | 
| 9 7 | 
             
              describe 'index action' do
         | 
| 10 8 | 
             
                before :each do
         | 
| @@ -12,13 +10,13 @@ describe InfoController do | |
| 12 10 | 
             
                end
         | 
| 13 11 |  | 
| 14 12 | 
             
                it 'should not fail' do
         | 
| 15 | 
            -
                   | 
| 16 | 
            -
                  expect{  | 
| 13 | 
            +
                  context.stub(:haml)
         | 
| 14 | 
            +
                  expect{ controller.index }.not_to raise_error
         | 
| 17 15 | 
             
                end
         | 
| 18 16 |  | 
| 19 17 | 
             
                it 'should render info template' do
         | 
| 20 | 
            -
                   | 
| 21 | 
            -
                   | 
| 18 | 
            +
                  context.should_receive(:haml).with('info/info'.to_sym, anything)
         | 
| 19 | 
            +
                  controller.index
         | 
| 22 20 | 
             
                end
         | 
| 23 21 | 
             
              end
         | 
| 24 22 | 
             
            end
         | 
| @@ -1,23 +1,21 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe PerformanceController do
         | 
| 4 | 
            -
               | 
| 5 | 
            -
             | 
| 6 | 
            -
                @controller = PerformanceController.new(context: @context)
         | 
| 7 | 
            -
              end
         | 
| 4 | 
            +
              let(:context){ double() }
         | 
| 5 | 
            +
              let(:controller){ PerformanceController.new(context: context) }
         | 
| 8 6 |  | 
| 9 7 | 
             
              describe 'warning action' do
         | 
| 10 8 | 
             
                it 'should render warning template' do
         | 
| 11 | 
            -
                   | 
| 12 | 
            -
                   | 
| 9 | 
            +
                  context.should_receive(:haml).with('performance/warning'.to_sym, anything)
         | 
| 10 | 
            +
                  controller.warning
         | 
| 13 11 | 
             
                end
         | 
| 14 12 | 
             
              end
         | 
| 15 13 |  | 
| 16 14 | 
             
              describe 'check action' do
         | 
| 17 15 | 
             
                it 'should render check template' do
         | 
| 18 16 | 
             
                  Backend.stub(:performance_stats){ {} }
         | 
| 19 | 
            -
                   | 
| 20 | 
            -
                   | 
| 17 | 
            +
                  context.should_receive(:haml).with('performance/check'.to_sym, anything)
         | 
| 18 | 
            +
                  controller.check
         | 
| 21 19 | 
             
                end
         | 
| 22 20 | 
             
              end
         | 
| 23 21 | 
             
            end
         | 
| @@ -1,18 +1,12 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe Backend do
         | 
| 4 | 
            +
              let(:redis){ double(del: '') }
         | 
| 5 | 
            +
             | 
| 4 6 | 
             
              before :each do
         | 
| 5 7 | 
             
                Backend.stub(:host)
         | 
| 6 8 | 
             
                Backend.stub(:port)
         | 
| 7 | 
            -
                 | 
| 8 | 
            -
              end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
              describe 'redis' do
         | 
| 11 | 
            -
                it 'create only one connection' do
         | 
| 12 | 
            -
                  Redis.should_receive(:new).once
         | 
| 13 | 
            -
                  Backend.redis
         | 
| 14 | 
            -
                  Backend.redis
         | 
| 15 | 
            -
                end
         | 
| 9 | 
            +
                Backend.stub(:redis){ redis }
         | 
| 16 10 | 
             
              end
         | 
| 17 11 |  | 
| 18 12 | 
             
              describe 'performance_stats' do
         | 
| @@ -43,4 +37,18 @@ describe Backend do | |
| 43 37 | 
             
                  Backend.search('*')[0][:value].should_not be_nil
         | 
| 44 38 | 
             
                end
         | 
| 45 39 | 
             
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              describe 'del' do
         | 
| 42 | 
            +
                it 'should not delete content if not allowed' do
         | 
| 43 | 
            +
                  Authorization.stub(:authorized_for?).with(:remove_content){ false }
         | 
| 44 | 
            +
                  redis.should_receive(:del).never
         | 
| 45 | 
            +
                  Backend.del('key')
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                it 'should remove content if allowed' do
         | 
| 49 | 
            +
                  Authorization.stub(:authorized_for?).with(:remove_content){ true }
         | 
| 50 | 
            +
                  redis.should_receive(:del)
         | 
| 51 | 
            +
                  Backend.del('key')
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 46 54 | 
             
            end
         | 
| @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Authentication do
         | 
| 4 | 
            +
              let(:server){ double(class_eval: nil, use: nil) }
         | 
| 5 | 
            +
              let(:credentials){ {user: 'user', password: 'password'} }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              describe 'config' do
         | 
| 8 | 
            +
                it 'should inject authentication in server class' do
         | 
| 9 | 
            +
                  Authentication.should_receive(:inject_authentication)
         | 
| 10 | 
            +
                  Authentication.config(server, credentials)
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              describe 'inject_authentication' do
         | 
| 15 | 
            +
                before :each do
         | 
| 16 | 
            +
                  Authentication.config(server, credentials)
         | 
| 17 | 
            +
                  server.stub(:class_eval){|&block| block.call }
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                it 'should include authentication if required' do
         | 
| 21 | 
            +
                  Authentication.stub(:authentication_required?){ true }
         | 
| 22 | 
            +
                  Authentication.should_receive(:use).with(Rack::Auth::Basic, anything)
         | 
| 23 | 
            +
                  Authentication.inject_authentication
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                it 'should not include authentication if not required' do
         | 
| 27 | 
            +
                  Authentication.stub(:authentication_required?){ false }
         | 
| 28 | 
            +
                  Authentication.should_not_receive(:use)
         | 
| 29 | 
            +
                  Authentication.inject_authentication
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              describe 'authentication_required??' do
         | 
| 34 | 
            +
                before :each do
         | 
| 35 | 
            +
                  Authentication.stub(:inject_authentication)
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                it 'should return true if it has some credentials' do
         | 
| 39 | 
            +
                  Authentication.config(server, credentials)
         | 
| 40 | 
            +
                  Authentication.authentication_required?.should eq(true)
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                it 'should return false if no credentials were provided' do
         | 
| 44 | 
            +
                  Authentication.config(server, nil)
         | 
| 45 | 
            +
                  Authentication.authentication_required?.should eq(false)
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
            end
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Authorization do
         | 
| 4 | 
            +
              describe 'authorized_for?' do
         | 
| 5 | 
            +
                it 'should return true if the permission exists and its value is true' do
         | 
| 6 | 
            +
                  Authorization.stub(:permissions){ {action: true} }
         | 
| 7 | 
            +
                  Authorization.authorized_for?(:action).should == true
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                it 'should return false if the permission does not exists or its value is false' do
         | 
| 11 | 
            +
                  Authorization.stub(:permissions){ {action: false} }
         | 
| 12 | 
            +
                  Authorization.authorized_for?(:action).should == false
         | 
| 13 | 
            +
                  Authorization.authorized_for?(:action2).should == false
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
| @@ -22,5 +22,21 @@ describe CommandLineParser do | |
| 22 22 | 
             
                  CommandLineParser.parse(args)[:redis_port].should eq(4444)
         | 
| 23 23 | 
             
                end
         | 
| 24 24 |  | 
| 25 | 
            +
                it 'should read editable option' do
         | 
| 26 | 
            +
                  args = ['--editable']
         | 
| 27 | 
            +
                  CommandLineParser.parse(args)[:permissions][:remove_content].should eq(true)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                it 'should read not-editable option' do
         | 
| 31 | 
            +
                  args = ['--not-editable']
         | 
| 32 | 
            +
                  CommandLineParser.parse(args)[:permissions][:remove_content].should eq(false)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                it 'should read credentials options' do
         | 
| 36 | 
            +
                  args = ['--credentials', 'user:password']
         | 
| 37 | 
            +
                  credentials = CommandLineParser.parse(args)[:credentials]
         | 
| 38 | 
            +
                  credentials[:user].should eq('user')
         | 
| 39 | 
            +
                  credentials[:password].should eq('password')
         | 
| 40 | 
            +
                end
         | 
| 25 41 | 
             
              end
         | 
| 26 42 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -10,11 +10,14 @@ RSpec.configure do |config| | |
| 10 10 | 
             
              config.order = 'random'
         | 
| 11 11 | 
             
            end
         | 
| 12 12 |  | 
| 13 | 
            +
            require 'sinatra'
         | 
| 13 14 | 
             
            require 'modules/helpers'
         | 
| 14 15 | 
             
            require 'modules/controllers'
         | 
| 15 16 | 
             
            require 'modules/backend'
         | 
| 16 17 | 
             
            require 'server/command_line_parser'
         | 
| 18 | 
            +
            require 'modules/security/authorization'
         | 
| 19 | 
            +
            require 'modules/security/authentication'
         | 
| 17 20 |  | 
| 18 21 | 
             
            include RedisMonitor
         | 
| 19 22 | 
             
            include RedisMonitor::Controllers
         | 
| 20 | 
            -
            include RedisMonitor::Errors
         | 
| 23 | 
            +
            include RedisMonitor::Errors
         | 
    
        metadata
    CHANGED
    
    | @@ -1,18 +1,20 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: redis_monitor
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.6
         | 
| 5 | 
            +
              prerelease: 
         | 
| 5 6 | 
             
            platform: ruby
         | 
| 6 7 | 
             
            authors:
         | 
| 7 8 | 
             
            - Javier Jimenez
         | 
| 8 9 | 
             
            autorequire: 
         | 
| 9 10 | 
             
            bindir: bin
         | 
| 10 11 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 12 | 
            +
            date: 2014-01-04 00:00:00.000000000 Z
         | 
| 12 13 | 
             
            dependencies:
         | 
| 13 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 15 | 
             
              name: sinatra
         | 
| 15 16 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 16 18 | 
             
                requirements:
         | 
| 17 19 | 
             
                - - ~>
         | 
| 18 20 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -20,27 +22,31 @@ dependencies: | |
| 20 22 | 
             
              type: :runtime
         | 
| 21 23 | 
             
              prerelease: false
         | 
| 22 24 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            +
                none: false
         | 
| 23 26 | 
             
                requirements:
         | 
| 24 27 | 
             
                - - ~>
         | 
| 25 28 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 29 | 
             
                    version: '1.4'
         | 
| 27 30 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            -
              name:  | 
| 31 | 
            +
              name: webrick
         | 
| 29 32 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 33 | 
            +
                none: false
         | 
| 30 34 | 
             
                requirements:
         | 
| 31 | 
            -
                - - '>='
         | 
| 35 | 
            +
                - - ! '>='
         | 
| 32 36 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 37 | 
             
                    version: '0'
         | 
| 34 38 | 
             
              type: :runtime
         | 
| 35 39 | 
             
              prerelease: false
         | 
| 36 40 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            +
                none: false
         | 
| 37 42 | 
             
                requirements:
         | 
| 38 | 
            -
                - - '>='
         | 
| 43 | 
            +
                - - ! '>='
         | 
| 39 44 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 45 | 
             
                    version: '0'
         | 
| 41 46 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 47 | 
             
              name: redis
         | 
| 43 48 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 | 
            +
                none: false
         | 
| 44 50 | 
             
                requirements:
         | 
| 45 51 | 
             
                - - ~>
         | 
| 46 52 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -48,6 +54,7 @@ dependencies: | |
| 48 54 | 
             
              type: :runtime
         | 
| 49 55 | 
             
              prerelease: false
         | 
| 50 56 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
                none: false
         | 
| 51 58 | 
             
                requirements:
         | 
| 52 59 | 
             
                - - ~>
         | 
| 53 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -55,6 +62,7 @@ dependencies: | |
| 55 62 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 63 | 
             
              name: haml
         | 
| 57 64 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                none: false
         | 
| 58 66 | 
             
                requirements:
         | 
| 59 67 | 
             
                - - ~>
         | 
| 60 68 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -62,13 +70,47 @@ dependencies: | |
| 62 70 | 
             
              type: :runtime
         | 
| 63 71 | 
             
              prerelease: false
         | 
| 64 72 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 73 | 
            +
                none: false
         | 
| 65 74 | 
             
                requirements:
         | 
| 66 75 | 
             
                - - ~>
         | 
| 67 76 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 77 | 
             
                    version: '4.0'
         | 
| 78 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 79 | 
            +
              name: will_paginate
         | 
| 80 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 81 | 
            +
                none: false
         | 
| 82 | 
            +
                requirements:
         | 
| 83 | 
            +
                - - ~>
         | 
| 84 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 85 | 
            +
                    version: '3.0'
         | 
| 86 | 
            +
              type: :runtime
         | 
| 87 | 
            +
              prerelease: false
         | 
| 88 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 89 | 
            +
                none: false
         | 
| 90 | 
            +
                requirements:
         | 
| 91 | 
            +
                - - ~>
         | 
| 92 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 93 | 
            +
                    version: '3.0'
         | 
| 94 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 95 | 
            +
              name: will_paginate-bootstrap
         | 
| 96 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 97 | 
            +
                none: false
         | 
| 98 | 
            +
                requirements:
         | 
| 99 | 
            +
                - - ! '>='
         | 
| 100 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 101 | 
            +
                    version: '0'
         | 
| 102 | 
            +
              type: :runtime
         | 
| 103 | 
            +
              prerelease: false
         | 
| 104 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 105 | 
            +
                none: false
         | 
| 106 | 
            +
                requirements:
         | 
| 107 | 
            +
                - - ! '>='
         | 
| 108 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 109 | 
            +
                    version: '0'
         | 
| 69 110 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 111 | 
             
              name: bundler
         | 
| 71 112 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 113 | 
            +
                none: false
         | 
| 72 114 | 
             
                requirements:
         | 
| 73 115 | 
             
                - - ~>
         | 
| 74 116 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -76,6 +118,7 @@ dependencies: | |
| 76 118 | 
             
              type: :development
         | 
| 77 119 | 
             
              prerelease: false
         | 
| 78 120 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                none: false
         | 
| 79 122 | 
             
                requirements:
         | 
| 80 123 | 
             
                - - ~>
         | 
| 81 124 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -83,20 +126,23 @@ dependencies: | |
| 83 126 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 84 127 | 
             
              name: rake
         | 
| 85 128 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 129 | 
            +
                none: false
         | 
| 86 130 | 
             
                requirements:
         | 
| 87 | 
            -
                - - '>='
         | 
| 131 | 
            +
                - - ! '>='
         | 
| 88 132 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 133 | 
             
                    version: '0'
         | 
| 90 134 | 
             
              type: :development
         | 
| 91 135 | 
             
              prerelease: false
         | 
| 92 136 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 137 | 
            +
                none: false
         | 
| 93 138 | 
             
                requirements:
         | 
| 94 | 
            -
                - - '>='
         | 
| 139 | 
            +
                - - ! '>='
         | 
| 95 140 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 141 | 
             
                    version: '0'
         | 
| 97 142 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 143 | 
             
              name: rspec
         | 
| 99 144 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 145 | 
            +
                none: false
         | 
| 100 146 | 
             
                requirements:
         | 
| 101 147 | 
             
                - - ~>
         | 
| 102 148 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -104,6 +150,7 @@ dependencies: | |
| 104 150 | 
             
              type: :development
         | 
| 105 151 | 
             
              prerelease: false
         | 
| 106 152 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 153 | 
            +
                none: false
         | 
| 107 154 | 
             
                requirements:
         | 
| 108 155 | 
             
                - - ~>
         | 
| 109 156 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -118,6 +165,7 @@ extra_rdoc_files: [] | |
| 118 165 | 
             
            files:
         | 
| 119 166 | 
             
            - .gitignore
         | 
| 120 167 | 
             
            - .rspec
         | 
| 168 | 
            +
            - .travis.yml
         | 
| 121 169 | 
             
            - Gemfile
         | 
| 122 170 | 
             
            - LICENSE.txt
         | 
| 123 171 | 
             
            - README.md
         | 
| @@ -131,11 +179,14 @@ files: | |
| 131 179 | 
             
            - lib/errors/redis_not_available.rb
         | 
| 132 180 | 
             
            - lib/helpers/base_helper.rb
         | 
| 133 181 | 
             
            - lib/helpers/layouts_helper.rb
         | 
| 182 | 
            +
            - lib/helpers/pagination_helper.rb
         | 
| 134 183 | 
             
            - lib/modules/backend.rb
         | 
| 135 184 | 
             
            - lib/modules/controllers.rb
         | 
| 136 185 | 
             
            - lib/modules/helpers.rb
         | 
| 137 186 | 
             
            - lib/modules/performance_stats.rb
         | 
| 138 187 | 
             
            - lib/modules/router.rb
         | 
| 188 | 
            +
            - lib/modules/security/authentication.rb
         | 
| 189 | 
            +
            - lib/modules/security/authorization.rb
         | 
| 139 190 | 
             
            - lib/modules/version.rb
         | 
| 140 191 | 
             
            - lib/redis_monitor.rb
         | 
| 141 192 | 
             
            - lib/server/command_line_parser.rb
         | 
| @@ -159,31 +210,34 @@ files: | |
| 159 210 | 
             
            - spec/controllers/performance_controller_spec.rb
         | 
| 160 211 | 
             
            - spec/modules/backend_spec.rb
         | 
| 161 212 | 
             
            - spec/modules/performance_stats_spec.rb
         | 
| 213 | 
            +
            - spec/modules/security/authentication_spec.rb
         | 
| 214 | 
            +
            - spec/modules/security/authorization_spec.rb
         | 
| 162 215 | 
             
            - spec/server/command_line_parser_spec.rb
         | 
| 163 216 | 
             
            - spec/spec_helper.rb
         | 
| 164 217 | 
             
            homepage: https://github.com/javiyu/redis_monitor
         | 
| 165 218 | 
             
            licenses:
         | 
| 166 219 | 
             
            - MIT
         | 
| 167 | 
            -
            metadata: {}
         | 
| 168 220 | 
             
            post_install_message: 
         | 
| 169 221 | 
             
            rdoc_options: []
         | 
| 170 222 | 
             
            require_paths:
         | 
| 171 223 | 
             
            - lib
         | 
| 172 224 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 225 | 
            +
              none: false
         | 
| 173 226 | 
             
              requirements:
         | 
| 174 | 
            -
              - - '>='
         | 
| 227 | 
            +
              - - ! '>='
         | 
| 175 228 | 
             
                - !ruby/object:Gem::Version
         | 
| 176 229 | 
             
                  version: '0'
         | 
| 177 230 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 231 | 
            +
              none: false
         | 
| 178 232 | 
             
              requirements:
         | 
| 179 | 
            -
              - - '>='
         | 
| 233 | 
            +
              - - ! '>='
         | 
| 180 234 | 
             
                - !ruby/object:Gem::Version
         | 
| 181 235 | 
             
                  version: '0'
         | 
| 182 236 | 
             
            requirements: []
         | 
| 183 237 | 
             
            rubyforge_project: 
         | 
| 184 | 
            -
            rubygems_version:  | 
| 238 | 
            +
            rubygems_version: 1.8.23
         | 
| 185 239 | 
             
            signing_key: 
         | 
| 186 | 
            -
            specification_version:  | 
| 240 | 
            +
            specification_version: 3
         | 
| 187 241 | 
             
            summary: Get general information of a running redis instance
         | 
| 188 242 | 
             
            test_files:
         | 
| 189 243 | 
             
            - spec/controllers/base_controller_spec.rb
         | 
| @@ -192,5 +246,7 @@ test_files: | |
| 192 246 | 
             
            - spec/controllers/performance_controller_spec.rb
         | 
| 193 247 | 
             
            - spec/modules/backend_spec.rb
         | 
| 194 248 | 
             
            - spec/modules/performance_stats_spec.rb
         | 
| 249 | 
            +
            - spec/modules/security/authentication_spec.rb
         | 
| 250 | 
            +
            - spec/modules/security/authorization_spec.rb
         | 
| 195 251 | 
             
            - spec/server/command_line_parser_spec.rb
         | 
| 196 252 | 
             
            - spec/spec_helper.rb
         | 
    
        checksums.yaml
    DELETED
    
    | @@ -1,7 +0,0 @@ | |
| 1 | 
            -
            ---
         | 
| 2 | 
            -
            SHA1:
         | 
| 3 | 
            -
              metadata.gz: 79092e09550d8bcba8120074790e62443fd811ab
         | 
| 4 | 
            -
              data.tar.gz: add45fdc52392f1f031555b680509f587ad7224b
         | 
| 5 | 
            -
            SHA512:
         | 
| 6 | 
            -
              metadata.gz: 2e1da2f8ffa882d255f841ee2420c92ca5dd2e0064a4d503be353d95069aa972683767d668fcde2891dce2dac3da570d9b9f280a5896ebe774275b06f049eb74
         | 
| 7 | 
            -
              data.tar.gz: eaf4029ffd01a860eca9f4006a484e3f2c631a9afceac765ab8392d47fd9e83e9452e102c61378a0c3a077e49488d36246c820f12d183953503b6fcb3435fbd9
         |