diff options
| -rw-r--r-- | lib/saml/kit/cli/commands/metadata.rb | 3 | ||||
| -rw-r--r-- | spec/saml/kit/cli/commands/metadata_spec.rb | 44 |
2 files changed, 29 insertions, 18 deletions
diff --git a/lib/saml/kit/cli/commands/metadata.rb b/lib/saml/kit/cli/commands/metadata.rb index 826e39d..6701d70 100644 --- a/lib/saml/kit/cli/commands/metadata.rb +++ b/lib/saml/kit/cli/commands/metadata.rb @@ -10,6 +10,9 @@ module Saml desc 'list', "List each of the registered entityId's" def list + if registry.count.zero? + say "Please register metadata using `saml-kit metadata register <url>`" + end registry.each do |x| say x.entity_id, :green end diff --git a/spec/saml/kit/cli/commands/metadata_spec.rb b/spec/saml/kit/cli/commands/metadata_spec.rb index 44c6bf8..a654922 100644 --- a/spec/saml/kit/cli/commands/metadata_spec.rb +++ b/spec/saml/kit/cli/commands/metadata_spec.rb @@ -1,13 +1,13 @@ RSpec.describe Saml::Kit::Cli::Commands::Metadata do let(:entity_id) { 'https://saml-kit-proof.herokuapp.com/metadata' } + let(:env) { "SAMLKITRC=#{tempfile}" } + let(:tempfile) { Tempfile.new('saml-kit').path } + + after { File.unlink(tempfile) if File.exist?(tempfile) } describe "#register" do - let(:env) { "SAMLKITRC=#{tempfile}" } - let(:tempfile) { Tempfile.new('saml-kit').path } let(:command) { "metadata register #{entity_id}" } - after { File.unlink(tempfile) } - specify { expect(status).to be_success } specify { expect(output).to include(entity_id) } specify { expect(output).to match(/EntityDescriptor/) } @@ -15,26 +15,34 @@ RSpec.describe Saml::Kit::Cli::Commands::Metadata do end describe "#show" do - before :each do - env = "SAMLKITRC=#{Tempfile.new('saml-kit').path}" - execute("metadata register #{entity_id}", env: env) - end - let(:command) { "metadata show #{entity_id}" } - specify { expect(status).to be_success } - specify { expect(output).to include(entity_id) } - end + context "when the entity_id is registered" do + before { execute("metadata register #{entity_id}") } - describe "#list" do - before :each do - env = "SAMLKITRC=#{Tempfile.new('saml-kit').path}" - execute("metadata register #{entity_id}", env: env) + specify { expect(status).to be_success } + specify { expect(output).to include(entity_id) } + end + + context "when the entity_id is not registered" do + specify { expect(status).to be_success } + specify { expect(output).to include("`#{entity_id}` is not registered") } end + end + describe "#list" do let(:command) { "metadata list" } - specify { expect(status).to be_success } - specify { expect(output).to include(entity_id) } + context "when a metadata is registered" do + before { execute("metadata register #{entity_id}") } + + specify { expect(status).to be_success } + specify { expect(output).to include(entity_id) } + end + + context "when zero metadata is registered" do + specify { expect(status).to be_success } + specify { expect(output).to include("Please register metadata using `saml-kit metadata register <url>`") } + end end end |
