Permalink
Browse files

Add empty admin page protected by Rack simple auth

See #39
  • Loading branch information...
Bounga committed Feb 6, 2018
1 parent 5c528c0 commit 635b40349d13f258ca93c41f3eb493fafe569674
@@ -261,6 +261,11 @@ class Application < Hanami::Application
controller.prepare do
# include MyAuthentication # included in all the actions
# before :authenticate! # run an authentication before callback
use Rack::Auth::Basic, 'Admin' do |username, password|
username == ENV.fetch('ADMIN_USERNAME', 'hanami') &&
password == ENV.fetch('ADMIN_PASSWORD', 'hanami')
end
end
# Configure the code that will yield each time Admin::View is included
@@ -3,3 +3,4 @@
#
# Example:
# get '/hello', to: ->(env) { [200, {}, ['Hello from Hanami!']] }
get '/', to: 'projects#index', as: :projects
@@ -0,0 +1,8 @@
module Admin::Controllers::Projects
class Index
include Admin::Action
def call(params)
end
end
end
@@ -0,0 +1 @@
p Here will be all projects!
@@ -0,0 +1,5 @@
module Admin::Views::Projects
class Index
include Admin::View
end
end
@@ -0,0 +1,9 @@
RSpec.describe Admin::Controllers::Projects::Index, type: :action do
let(:action) { described_class.new }
let(:params) { Hash[] }
it 'is successful' do
response = action.call(params)
expect(response[0]).to eq 200
end
end
@@ -0,0 +1,33 @@
require 'spec_helper'
describe "Admin index" do
include Rack::Test::Methods
def app
Hanami.app
end
it "is unauthorized without auth" do
get "/admin"
expect(last_response.status).to eq 401
end
it "is unauthorized with bad auth" do
encoded_login = ["bad:credentials"].pack('m0')
header('Authorization', "Basic #{encoded_login}")
get "/admin"
expect(last_response.status).to eq 401
end
it "is succesful with valid auth" do
username = ENV.fetch('ADMIN_USERNAME', 'hanami')
password = ENV.fetch('ADMIN_PASSWORD', 'hanami')
encoded_login = ["#{username}:#{password}"].pack('m0')
header('Authorization', "Basic #{encoded_login}")
get "/admin"
expect(last_response.status).to eq 200
end
end
@@ -0,0 +1,6 @@
RSpec.describe Admin::Views::Projects::Index, type: :view do
let(:exposures) { Hash[foo: 'bar'] }
let(:template) { Hanami::View::Template.new('apps/admin/templates/projects/index.html.slim') }
let(:view) { described_class.new(template, exposures) }
let(:rendered) { view.render }
end

0 comments on commit 635b403

Please sign in to comment.