razoul 0.0.0 → 0.0.2
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 +4 -4
- data/README.md +50 -0
- data/lib/razoul.rb +34 -1
- data/lib/razoul/configuration.rb +17 -0
- data/lib/razoul/controller.rb +7 -0
- data/lib/razoul/controllers/authentication_controller.rb +14 -0
- data/lib/razoul/controllers/generator_controller.rb +23 -0
- data/lib/razoul/logger.rb +15 -0
- data/lib/razoul/model.rb +9 -0
- data/lib/razoul/persistence/database.rb +35 -0
- data/lib/razoul/persistence/redis.rb +34 -0
- data/lib/razoul/token.rb +38 -0
- data/lib/razoul/user.rb +8 -0
- data/lib/razoul/version.rb +4 -0
- data/spec/fixtures/razoul.yml +7 -0
- data/spec/lib/razoul/configuration_spec.rb +54 -0
- data/spec/lib/razoul/controller_spec.rb +11 -0
- data/spec/lib/razoul/controllers/authentication_controller_spec.rb +38 -0
- data/spec/lib/razoul/controllers/generator_controller_spec.rb +8 -0
- data/spec/lib/razoul/persistence/database_spec.rb +10 -0
- data/spec/lib/razoul/persistence/redis_spec.rb +39 -0
- data/spec/lib/razoul/token_spec.rb +48 -0
- data/spec/lib/razoul_spec.rb +33 -0
- data/spec/spec_helper.rb +28 -0
- metadata +221 -7
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7e9e0007ed765ca8e7dea2a00de512787b190532
         | 
| 4 | 
            +
              data.tar.gz: cfbb45cab2855ec041f3366efc896a51b7ad1502
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a1ce66848ee0f691da04ab8df79e0b0514d9df8ed0257e39b0ac3b03b1a7a5a5e0bab8d202bf2092131cb62bdc3549892c178f62ae40d55f6520769c56ed1053
         | 
| 7 | 
            +
              data.tar.gz: 3fe669181533fe827e674e9f3484b24c273c55bae4e1f8e08d42104cedac5347e5871d3877500ace84e0ffbb9ee4015c50f981afd77e17be49c8b9a01bade9d1
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            # Razoul
         | 
| 2 | 
            +
            Gem for generate token to Auth
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # Installation
         | 
| 5 | 
            +
            To use this gem add this line in your Gemfile
         | 
| 6 | 
            +
            ```ruby
         | 
| 7 | 
            +
            gem 'razoul'
         | 
| 8 | 
            +
            ```
         | 
| 9 | 
            +
            # Configuration
         | 
| 10 | 
            +
            In Rails applications create a razoul.rb in config/initializers
         | 
| 11 | 
            +
            ```ruby
         | 
| 12 | 
            +
            require 'razoul'
         | 
| 13 | 
            +
            Razoul.configure do |config|
         | 
| 14 | 
            +
               config.login = 'razoul'
         | 
| 15 | 
            +
               config.password = '123456'
         | 
| 16 | 
            +
               config.persistence = 'redis'
         | 
| 17 | 
            +
               config.redis_password  = '1234'
         | 
| 18 | 
            +
               config.token_key = 'RAZOUL_AUTH_KEY'
         | 
| 19 | 
            +
               config.prefix_token = 'RAZOUL'
         | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            ```
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            # Usage
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            Razoul need one controller to generate and get current token, to do tthis you need create a controller and extend this of Razoul::GeneratorController
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ```ruby
         | 
| 29 | 
            +
            class YourController < Razoul::GeneratorController
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            ```
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            This controller have two routes
         | 
| 34 | 
            +
            ```ruby
         | 
| 35 | 
            +
            resource :yourcontroller do
         | 
| 36 | 
            +
            get :new, :show
         | 
| 37 | 
            +
            end
         | 
| 38 | 
            +
            ```
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            To get new token and get current, pass prefix_token(RAZOUL) + login and password in header of request
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            In controller you need some authentication you need add a before_action :authenticate
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            ```ruby
         | 
| 45 | 
            +
            class ResourceController < Razoul::Controller
         | 
| 46 | 
            +
            before_action :authenticate, :only [:<controller api action>]
         | 
| 47 | 
            +
            ```
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            And to use this resource, pass token in token_key(RAZOUL_AUTH_KEY) in header
         | 
| 50 | 
            +
             | 
    
        data/lib/razoul.rb
    CHANGED
    
    | @@ -1,3 +1,36 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            require 'slogger'
         | 
| 2 | 
            +
            require 'redis'
         | 
| 3 | 
            +
            require 'action_pack'
         | 
| 4 | 
            +
            require 'action_controller'
         | 
| 5 | 
            +
            require 'razoul/configuration'
         | 
| 6 | 
            +
            require 'razoul/persistence/database'
         | 
| 7 | 
            +
            require 'razoul/user'
         | 
| 8 | 
            +
            require 'razoul/controller'
         | 
| 9 | 
            +
            require 'razoul/controllers/authentication_controller'
         | 
| 10 | 
            +
            require 'razoul/controllers/generator_controller'
         | 
| 11 | 
            +
            require 'razoul/persistence/redis'
         | 
| 12 | 
            +
            require 'razoul/model'
         | 
| 13 | 
            +
            require 'razoul/token'
         | 
| 2 14 |  | 
| 15 | 
            +
            module Razoul
         | 
| 16 | 
            +
             class << self
         | 
| 17 | 
            +
               attr_writer :configuration
         | 
| 18 | 
            +
             end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
             def self.configuration
         | 
| 21 | 
            +
               @configuration ||= Configuration.new
         | 
| 22 | 
            +
             end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
             def self.reset
         | 
| 25 | 
            +
               @configuration = Configuration.new
         | 
| 26 | 
            +
             end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
             begin
         | 
| 29 | 
            +
               require 'pry'
         | 
| 30 | 
            +
             rescue LoadError
         | 
| 31 | 
            +
             end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def self.configure
         | 
| 34 | 
            +
                yield(configuration)
         | 
| 35 | 
            +
              end
         | 
| 3 36 | 
             
            end
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            module Razoul
         | 
| 2 | 
            +
              class Configuration
         | 
| 3 | 
            +
                attr_accessor :token_prefix, :database, :token_key, :login, :password, :expiration_time
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize
         | 
| 6 | 
            +
                  @token_prefix = 'Razoul_Auth'
         | 
| 7 | 
            +
                  @database = 'redis'
         | 
| 8 | 
            +
                  @token_key = 'RAZOUL_AUTH_KEY'
         | 
| 9 | 
            +
                  @expiration_time = 60
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def has_attr?(key)
         | 
| 13 | 
            +
                  respond_to?(key)
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            module Razoul
         | 
| 2 | 
            +
              class AuthenticationController < Razoul::Controller
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def authenticate!
         | 
| 5 | 
            +
                  @token = request.headers["HTTP_#{Razoul.configuration.token_key}"]
         | 
| 6 | 
            +
                  render_error unless valid_token?
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def valid_token?
         | 
| 10 | 
            +
                  @token.present? ? Razoul::Token.valid_token?(@token) : false
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            module Razoul
         | 
| 2 | 
            +
              class GeneratorController < Razoul::Controller
         | 
| 3 | 
            +
                before_action :authenticate!
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def new
         | 
| 6 | 
            +
                  render json: Razoul::Token.generate!
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def show
         | 
| 10 | 
            +
                  render json: Razoul::Token.current_token
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def authenticate!
         | 
| 14 | 
            +
                  render_error unless Razoul::User.authenticate(auth_params)
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                private
         | 
| 18 | 
            +
                def auth_params
         | 
| 19 | 
            +
                  {login: request.headers['HTTP_RAZOUL_LOGIN'],
         | 
| 20 | 
            +
                   password: request.headers['HTTP_RAZOUL_PASSWORD']}
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            module Razoul
         | 
| 2 | 
            +
              class Logger
         | 
| 3 | 
            +
                SEVERITY_LEVEL = :info
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                attr_accessor :logger
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize
         | 
| 8 | 
            +
                  @logger = Slogger::Logger.new 'Razoul', SEVERITY_LEVEL, :local0
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def log(msg, severity = SEVERITY_LEVEL)
         | 
| 12 | 
            +
                  @logger.send SEVERITY_LEVEL, msg
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
    
        data/lib/razoul/model.rb
    ADDED
    
    
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            module Razoul
         | 
| 2 | 
            +
              module Persistence
         | 
| 3 | 
            +
                class Database
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                  attr_accessor :configuration
         | 
| 6 | 
            +
                  attr_writer :connection
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def initialize(config = Razoul.configuration)
         | 
| 9 | 
            +
                    @configuration = config
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def conn
         | 
| 13 | 
            +
                    @connection ||= call_module.configure(call_class, @configuration)
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def save(key, value)
         | 
| 17 | 
            +
                    call_module.save(conn, key, value)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  def find(key)
         | 
| 21 | 
            +
                    call_module.find(conn, key)
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  private
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def call_module
         | 
| 27 | 
            +
                    Module.const_get("::Razoul::Persistence::#{@configuration.database.capitalize}")
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def call_class
         | 
| 31 | 
            +
                    Object.const_get("::#{@configuration.database.capitalize}")
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            module Razoul
         | 
| 2 | 
            +
              module Persistence
         | 
| 3 | 
            +
                module Redis
         | 
| 4 | 
            +
                  HOST            = '127.0.0.1'
         | 
| 5 | 
            +
                  PORT            = 6379
         | 
| 6 | 
            +
                  DB              = 0
         | 
| 7 | 
            +
                  @conn           = nil
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  class << self
         | 
| 10 | 
            +
                    def configure(class_name, config)
         | 
| 11 | 
            +
                      class_name.new(hash_config_attrs(config))
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    def save(conn, key, value)
         | 
| 15 | 
            +
                      conn.set(key, value).eql?('OK') ? true : false
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    def find(conn, key)
         | 
| 19 | 
            +
                      conn.get(key)
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    def hash_config_attrs(config)
         | 
| 23 | 
            +
                      hash = {}
         | 
| 24 | 
            +
                      constants.map do |const|
         | 
| 25 | 
            +
                        value =  config.has_attr?("#{self.class.name}_#{const.downcase}") ?
         | 
| 26 | 
            +
                          config.send("#{self.class.name}_#{const.downcase}") : const_get(const)
         | 
| 27 | 
            +
                        hash.merge!(const.downcase.to_sym =>  value)
         | 
| 28 | 
            +
                      end
         | 
| 29 | 
            +
                      hash
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
    
        data/lib/razoul/token.rb
    ADDED
    
    | @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            require 'pry'
         | 
| 2 | 
            +
            module Razoul
         | 
| 3 | 
            +
              class Token < Model
         | 
| 4 | 
            +
                attr_accessor :value, :created_at
         | 
| 5 | 
            +
                private_class_method :new
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize
         | 
| 8 | 
            +
                  @value = self.generate_key
         | 
| 9 | 
            +
                  @created_at = Time.now.to_i
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def generate_key
         | 
| 13 | 
            +
                  digest = OpenSSL::Digest::SHA256.new
         | 
| 14 | 
            +
                  secret = Razoul.configuration.password
         | 
| 15 | 
            +
                  string = Razoul.configuration.login + Time.now.to_s
         | 
| 16 | 
            +
                  OpenSSL::HMAC.hexdigest(digest, secret, string)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def expired?
         | 
| 20 | 
            +
                  puts "Time now: #{Time.now.to_i} - #{self.created_at}"
         | 
| 21 | 
            +
                  Time.now.to_i - self.created_at >= Razoul.configuration.expiration_time
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                class << self
         | 
| 25 | 
            +
                  def current_token
         | 
| 26 | 
            +
                    Marshal.load(persistence.find(Razoul.configuration.token_key))
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  def generate!
         | 
| 30 | 
            +
                    persistence.save(Razoul.configuration.token_key, Marshal.dump(new))
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def valid_token?(token)
         | 
| 34 | 
            +
                    token.eql?(Marshal.load(persistence.find(Razoul.configuration.token_key)).value) ? true : false
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
    
        data/lib/razoul/user.rb
    ADDED
    
    
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
            RSpec.describe Razoul::Configuration do
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              subject(:instance) { described_class.new }
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              describe '#token_prefix' do
         | 
| 7 | 
            +
                subject { instance }
         | 
| 8 | 
            +
                  its(:token_prefix) { is_expected.to eq  'Razoul_Auth' }
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              describe '#token_prefix=' do
         | 
| 12 | 
            +
                it 'can set value' do
         | 
| 13 | 
            +
                  instance.token_prefix  =  'Razoul_Auth_Prefix'
         | 
| 14 | 
            +
                  expect(instance.token_prefix).to eq 'Razoul_Auth_Prefix'
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              describe '#database' do
         | 
| 19 | 
            +
                subject { instance }
         | 
| 20 | 
            +
                  its(:database) { is_expected.to eq  'redis' }
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              describe '#database=' do
         | 
| 24 | 
            +
                it 'can set value' do
         | 
| 25 | 
            +
                  instance.database  =  'redis'
         | 
| 26 | 
            +
                  expect(instance.database).to eq 'redis'
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              describe '#token_key' do
         | 
| 31 | 
            +
                subject { instance }
         | 
| 32 | 
            +
                  its(:token_key) { is_expected.to eq  'RAZOUL_AUTH_KEY' }
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              describe '#token_key=' do
         | 
| 36 | 
            +
                it 'can set value' do
         | 
| 37 | 
            +
                  instance.token_key  =  'RAZOUL_KEY'
         | 
| 38 | 
            +
                  expect(instance.token_key).to eq 'RAZOUL_KEY'
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              describe '#expiration_time' do
         | 
| 43 | 
            +
                subject { instance }
         | 
| 44 | 
            +
                  its(:expiration_time) { is_expected.to eq  60 }
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              describe '#expiration_time=' do
         | 
| 48 | 
            +
                it 'can set value' do
         | 
| 49 | 
            +
                  instance.expiration_time  =  45
         | 
| 50 | 
            +
                  expect(instance.expiration_time).to eq 45
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
| 54 | 
            +
             | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            RSpec.describe Razoul::AuthenticationController, type: :controller do
         | 
| 4 | 
            +
              specify { expect(described_class.new).to be_a_kind_of ActionController::Base }
         | 
| 5 | 
            +
              let(:instance) { described_class.new }
         | 
| 6 | 
            +
              let(:request_double) { double }
         | 
| 7 | 
            +
              let(:request_hash)  do
         | 
| 8 | 
            +
                {"HTTP_#{Razoul.configuration.token_key}" => 'ADDSSDFSFSF' }
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              describe '#authenticate' do
         | 
| 12 | 
            +
                before do
         | 
| 13 | 
            +
                  allow(request_double).to receive(:headers).and_return(request_hash)
         | 
| 14 | 
            +
                  allow(instance).to receive(:request).and_return(request_double)
         | 
| 15 | 
            +
                  allow(Razoul::Token).to receive(:valid_token?).and_return(true)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                context 'when has a valid token' do
         | 
| 19 | 
            +
                  it 'dont call render_error ' do
         | 
| 20 | 
            +
                    expect(instance).to receive(:render_error).never
         | 
| 21 | 
            +
                    instance.authenticate!
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                context 'when hasnt a valid token' do
         | 
| 26 | 
            +
                  before do
         | 
| 27 | 
            +
                    allow(Razoul::Token).to receive(:valid_token?).and_return(false)
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  it 'call render_error ' do
         | 
| 31 | 
            +
                    expect(instance).to receive(:render_error).once
         | 
| 32 | 
            +
                    instance.authenticate!
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            end
         | 
| 38 | 
            +
             | 
| @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            RSpec.describe Razoul::Persistence::Redis do
         | 
| 4 | 
            +
              let(:config) { Razoul.configuration }
         | 
| 5 | 
            +
              let(:class_name) { ::Redis }
         | 
| 6 | 
            +
              let(:connection) { described_class.configure(class_name, config) }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              describe '#hash_config_attrs' do
         | 
| 9 | 
            +
                subject { described_class.hash_config_attrs(config) }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                it { is_expected.to be_a_kind_of (Hash) }
         | 
| 12 | 
            +
                its(:keys) { is_expected.to eq [:host, :port, :db] }
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              describe '#configure' do
         | 
| 16 | 
            +
                context 'when success' do
         | 
| 17 | 
            +
                  subject { described_class.configure(class_name, config) }
         | 
| 18 | 
            +
                  it { is_expected.to be_a_kind_of(::Redis) }
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              describe '#save' do
         | 
| 23 | 
            +
                let(:token_key)  { config.token_key }
         | 
| 24 | 
            +
                let(:value)      { "RAZOUL_TOKEN" }
         | 
| 25 | 
            +
                subject { described_class.save(connection, token_key, value) }
         | 
| 26 | 
            +
                it { is_expected.to eq true }
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              describe '#find' do
         | 
| 30 | 
            +
                let(:key)   { 'ADASDSADASDAS' }
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                before do
         | 
| 33 | 
            +
                  described_class.save(connection, key, key)
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                subject { described_class.find(connection, key) }
         | 
| 37 | 
            +
                it { is_expected.to eq key }
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
| @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            RSpec.describe Razoul::Token do
         | 
| 4 | 
            +
              before do
         | 
| 5 | 
            +
                Timecop.freeze(Time.now)
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              after do
         | 
| 9 | 
            +
                Timecop.return
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              let(:time_in_seconds) { Time.now.to_i }
         | 
| 13 | 
            +
              before :each do
         | 
| 14 | 
            +
                Razoul.configure do |config|
         | 
| 15 | 
            +
                  config.login = 'Razoul'
         | 
| 16 | 
            +
                  config.password = 'Razoul_AUTH'
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              describe '#generate!' do
         | 
| 21 | 
            +
                subject { described_class.generate! }
         | 
| 22 | 
            +
                it  { is_expected.to be_truthy }
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              describe '#expired?' do
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                context 'when expiration_time eql 1 minute' do
         | 
| 28 | 
            +
                  subject { described_class.current_token.expired? }
         | 
| 29 | 
            +
                  context 'when isn\'t expired' do
         | 
| 30 | 
            +
                    it { is_expected.to eq false }
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                context 'when expiration_time eql 1 second' do
         | 
| 35 | 
            +
                  before do
         | 
| 36 | 
            +
                    Timecop.travel(Time.now + 1)
         | 
| 37 | 
            +
                    Razoul.configure do |config|
         | 
| 38 | 
            +
                      config.expiration_time = 1
         | 
| 39 | 
            +
                    end
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  context 'when is expired' do
         | 
| 43 | 
            +
                    subject { described_class.current_token.expired? }
         | 
| 44 | 
            +
                    it { is_expected.to eq true }
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            RSpec.describe Razoul do
         | 
| 4 | 
            +
              describe '.reset' do
         | 
| 5 | 
            +
                before :each do
         | 
| 6 | 
            +
                  Razoul.configure do |config|
         | 
| 7 | 
            +
                    config.token_prefix = 'TEST'
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
                it 'reset the configuration' do
         | 
| 11 | 
            +
                  Razoul.reset
         | 
| 12 | 
            +
                  config  = Razoul.configuration
         | 
| 13 | 
            +
                  expect(config.token_prefix).to eq 'Razoul_Auth'
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
              
         | 
| 18 | 
            +
              
         | 
| 19 | 
            +
              describe '.configure' do
         | 
| 20 | 
            +
                let(:persistence) { Razoul::Persistence::Database.new }
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                before do 
         | 
| 23 | 
            +
                  Razoul.configure do |config|
         | 
| 24 | 
            +
                    config.token_prefix = 'PREFIX_RAZOUL'
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                context 'returns a token prefix' do
         | 
| 29 | 
            +
                  subject { persistence }
         | 
| 30 | 
            +
                  its(:'configuration.token_prefix') {  is_expected.to eq 'PREFIX_RAZOUL' }
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            require 'bundler/setup'
         | 
| 2 | 
            +
            require 'pry'
         | 
| 3 | 
            +
            require 'timecop'
         | 
| 4 | 
            +
            Bundler.setup
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            if ENV['COVERAGE']
         | 
| 7 | 
            +
              require 'simplecov'
         | 
| 8 | 
            +
              require 'simplecov-rcov'
         | 
| 9 | 
            +
              require 'simplecov-gem-adapter'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              SimpleCov.start 'gem' do
         | 
| 12 | 
            +
                formatter SimpleCov::Formatter::RcovFormatter
         | 
| 13 | 
            +
                add_filter '/spec/'
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            require 'rspec'
         | 
| 18 | 
            +
            require 'rspec/its'
         | 
| 19 | 
            +
            require 'webmock/rspec'
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            require 'razoul'
         | 
| 22 | 
            +
             | 
| 23 | 
            +
             | 
| 24 | 
            +
            RSpec.configure do |c|
         | 
| 25 | 
            +
              c.disable_monkey_patching!
         | 
| 26 | 
            +
            end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
             | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: razoul
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Gabriel Malaquias
         | 
| @@ -9,15 +9,219 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 | 
             
            date: 2015-07-20 00:00:00.000000000 Z
         | 
| 12 | 
            -
            dependencies: | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: redis
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 3.2.1
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: 3.2.1
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: slogger
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: actionpack
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: rspec
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: rspec-mocks
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - ">="
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - ">="
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: timecop
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - ">="
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '0'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - ">="
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '0'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: rspec-its
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ">="
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0'
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ">="
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0'
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: webmock
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - ">="
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '0'
         | 
| 118 | 
            +
              type: :development
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - ">="
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: '0'
         | 
| 125 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 126 | 
            +
              name: rubocop
         | 
| 127 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 128 | 
            +
                requirements:
         | 
| 129 | 
            +
                - - ">="
         | 
| 130 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            +
                    version: '0'
         | 
| 132 | 
            +
              type: :development
         | 
| 133 | 
            +
              prerelease: false
         | 
| 134 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 | 
            +
                requirements:
         | 
| 136 | 
            +
                - - ">="
         | 
| 137 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            +
                    version: '0'
         | 
| 139 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 140 | 
            +
              name: rubocop-rspec
         | 
| 141 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 | 
            +
                requirements:
         | 
| 143 | 
            +
                - - ">="
         | 
| 144 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            +
                    version: '0'
         | 
| 146 | 
            +
              type: :development
         | 
| 147 | 
            +
              prerelease: false
         | 
| 148 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 | 
            +
                requirements:
         | 
| 150 | 
            +
                - - ">="
         | 
| 151 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            +
                    version: '0'
         | 
| 153 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 154 | 
            +
              name: simplecov-rcov
         | 
| 155 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 156 | 
            +
                requirements:
         | 
| 157 | 
            +
                - - ">="
         | 
| 158 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 159 | 
            +
                    version: '0'
         | 
| 160 | 
            +
              type: :development
         | 
| 161 | 
            +
              prerelease: false
         | 
| 162 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 163 | 
            +
                requirements:
         | 
| 164 | 
            +
                - - ">="
         | 
| 165 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 166 | 
            +
                    version: '0'
         | 
| 167 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 168 | 
            +
              name: simplecov-gem-adapter
         | 
| 169 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 170 | 
            +
                requirements:
         | 
| 171 | 
            +
                - - ">="
         | 
| 172 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 173 | 
            +
                    version: '0'
         | 
| 174 | 
            +
              type: :development
         | 
| 175 | 
            +
              prerelease: false
         | 
| 176 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 177 | 
            +
                requirements:
         | 
| 178 | 
            +
                - - ">="
         | 
| 179 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 180 | 
            +
                    version: '0'
         | 
| 181 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 182 | 
            +
              name: simplecov
         | 
| 183 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 184 | 
            +
                requirements:
         | 
| 185 | 
            +
                - - ">="
         | 
| 186 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 187 | 
            +
                    version: '0'
         | 
| 188 | 
            +
              type: :development
         | 
| 189 | 
            +
              prerelease: false
         | 
| 190 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 191 | 
            +
                requirements:
         | 
| 192 | 
            +
                - - ">="
         | 
| 193 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 194 | 
            +
                    version: '0'
         | 
| 13 195 | 
             
            description: Gem for generate token to Auth
         | 
| 14 196 | 
             
            email: gabriel07malakias@gmail.com
         | 
| 15 197 | 
             
            executables: []
         | 
| 16 198 | 
             
            extensions: []
         | 
| 17 199 | 
             
            extra_rdoc_files: []
         | 
| 18 200 | 
             
            files:
         | 
| 201 | 
            +
            - README.md
         | 
| 19 202 | 
             
            - lib/razoul.rb
         | 
| 20 | 
            -
             | 
| 203 | 
            +
            - lib/razoul/configuration.rb
         | 
| 204 | 
            +
            - lib/razoul/controller.rb
         | 
| 205 | 
            +
            - lib/razoul/controllers/authentication_controller.rb
         | 
| 206 | 
            +
            - lib/razoul/controllers/generator_controller.rb
         | 
| 207 | 
            +
            - lib/razoul/logger.rb
         | 
| 208 | 
            +
            - lib/razoul/model.rb
         | 
| 209 | 
            +
            - lib/razoul/persistence/database.rb
         | 
| 210 | 
            +
            - lib/razoul/persistence/redis.rb
         | 
| 211 | 
            +
            - lib/razoul/token.rb
         | 
| 212 | 
            +
            - lib/razoul/user.rb
         | 
| 213 | 
            +
            - lib/razoul/version.rb
         | 
| 214 | 
            +
            - spec/fixtures/razoul.yml
         | 
| 215 | 
            +
            - spec/lib/razoul/configuration_spec.rb
         | 
| 216 | 
            +
            - spec/lib/razoul/controller_spec.rb
         | 
| 217 | 
            +
            - spec/lib/razoul/controllers/authentication_controller_spec.rb
         | 
| 218 | 
            +
            - spec/lib/razoul/controllers/generator_controller_spec.rb
         | 
| 219 | 
            +
            - spec/lib/razoul/persistence/database_spec.rb
         | 
| 220 | 
            +
            - spec/lib/razoul/persistence/redis_spec.rb
         | 
| 221 | 
            +
            - spec/lib/razoul/token_spec.rb
         | 
| 222 | 
            +
            - spec/lib/razoul_spec.rb
         | 
| 223 | 
            +
            - spec/spec_helper.rb
         | 
| 224 | 
            +
            homepage: https://github.com/GabrielMalakias/Razoul
         | 
| 21 225 | 
             
            licenses:
         | 
| 22 226 | 
             
            - MIT
         | 
| 23 227 | 
             
            metadata: {}
         | 
| @@ -27,18 +231,28 @@ require_paths: | |
| 27 231 | 
             
            - lib
         | 
| 28 232 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 29 233 | 
             
              requirements:
         | 
| 30 | 
            -
              - -  | 
| 234 | 
            +
              - - ">="
         | 
| 31 235 | 
             
                - !ruby/object:Gem::Version
         | 
| 32 236 | 
             
                  version: '0'
         | 
| 33 237 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 34 238 | 
             
              requirements:
         | 
| 35 | 
            -
              - -  | 
| 239 | 
            +
              - - ">="
         | 
| 36 240 | 
             
                - !ruby/object:Gem::Version
         | 
| 37 241 | 
             
                  version: '0'
         | 
| 38 242 | 
             
            requirements: []
         | 
| 39 243 | 
             
            rubyforge_project: 
         | 
| 40 | 
            -
            rubygems_version: 2. | 
| 244 | 
            +
            rubygems_version: 2.4.6
         | 
| 41 245 | 
             
            signing_key: 
         | 
| 42 246 | 
             
            specification_version: 4
         | 
| 43 247 | 
             
            summary: Gem for generate token to Auth
         | 
| 44 | 
            -
            test_files: | 
| 248 | 
            +
            test_files:
         | 
| 249 | 
            +
            - spec/lib/razoul/controllers/generator_controller_spec.rb
         | 
| 250 | 
            +
            - spec/lib/razoul/controllers/authentication_controller_spec.rb
         | 
| 251 | 
            +
            - spec/lib/razoul/controller_spec.rb
         | 
| 252 | 
            +
            - spec/lib/razoul/token_spec.rb
         | 
| 253 | 
            +
            - spec/lib/razoul/persistence/database_spec.rb
         | 
| 254 | 
            +
            - spec/lib/razoul/persistence/redis_spec.rb
         | 
| 255 | 
            +
            - spec/lib/razoul/configuration_spec.rb
         | 
| 256 | 
            +
            - spec/lib/razoul_spec.rb
         | 
| 257 | 
            +
            - spec/fixtures/razoul.yml
         | 
| 258 | 
            +
            - spec/spec_helper.rb
         |