Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the tmp/sessions dir if it doesn't exist #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/casclient/tickets/storage.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "fileutils"

module CASClient
module Tickets
module Storage
Expand Down Expand Up @@ -84,6 +86,7 @@ def initialize(config={})
@tmp_dir = config[:storage_dir] || default_tmp_dir
@service_session_lookup_dir = config[:service_session_lookup_dir] || "#{@tmp_dir}/sessions"
@pgt_store_path = config[:pgt_store_path] || "#{@tmp_dir}/cas_pgt.pstore"
create_service_session_lookup_dir
end

# Creates a file in tmp/sessions linking a SessionTicket
Expand Down Expand Up @@ -169,6 +172,12 @@ def filename_of_service_session_lookup(st)
def open_pstore
PStore.new(@pgt_store_path)
end

def create_service_session_lookup_dir
unless File.exist? @service_session_lookup_dir
FileUtils.mkdir_p @service_session_lookup_dir
end
end
end
end
end
Expand Down
25 changes: 20 additions & 5 deletions spec/casclient/tickets/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,28 @@

describe CASClient::Tickets::Storage::LocalDirTicketStore do
let(:dir) {File.join(SPEC_TMP_DIR, "local_dir_ticket_store")}
before do
FileUtils.mkdir_p(File.join(dir, "sessions"))
end

after do
FileUtils.remove_dir(dir)
end
it_should_behave_like "a ticket store" do
let(:ticket_store) {described_class.new(:storage_dir => dir)}

describe "when the sessions directory does not exist" do
before do
File.exist?(File.join(dir, "sessions")).should be_false
end

it_should_behave_like "a ticket store" do
let(:ticket_store) {described_class.new(:storage_dir => dir)}
end
end

describe "when the session directory exists" do
before do
FileUtils.mkdir_p(File.join(dir, "sessions"))
end

it_should_behave_like "a ticket store" do
let(:ticket_store) {described_class.new(:storage_dir => dir)}
end
end
end