diff --git a/Gemfile b/Gemfile index c84311c..248e3e6 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gemspec gem "rake", "~> 12.0" -gem "rspec", "~> 3.0" \ No newline at end of file +gem "rspec", "~> 3.0" + +group :test do + gem "rails", "~> 6.1.0" + gem "generator_spec" +end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 01551d1..ed625a1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,7 +6,119 @@ PATH GEM remote: https://rubygems.org/ specs: + actioncable (6.1.3.2) + actionpack (= 6.1.3.2) + activesupport (= 6.1.3.2) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.1.3.2) + actionpack (= 6.1.3.2) + activejob (= 6.1.3.2) + activerecord (= 6.1.3.2) + activestorage (= 6.1.3.2) + activesupport (= 6.1.3.2) + mail (>= 2.7.1) + actionmailer (6.1.3.2) + actionpack (= 6.1.3.2) + actionview (= 6.1.3.2) + activejob (= 6.1.3.2) + activesupport (= 6.1.3.2) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (6.1.3.2) + actionview (= 6.1.3.2) + activesupport (= 6.1.3.2) + rack (~> 2.0, >= 2.0.9) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.3.2) + actionpack (= 6.1.3.2) + activerecord (= 6.1.3.2) + activestorage (= 6.1.3.2) + activesupport (= 6.1.3.2) + nokogiri (>= 1.8.5) + actionview (6.1.3.2) + activesupport (= 6.1.3.2) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.3.2) + activesupport (= 6.1.3.2) + globalid (>= 0.3.6) + activemodel (6.1.3.2) + activesupport (= 6.1.3.2) + activerecord (6.1.3.2) + activemodel (= 6.1.3.2) + activesupport (= 6.1.3.2) + activestorage (6.1.3.2) + actionpack (= 6.1.3.2) + activejob (= 6.1.3.2) + activerecord (= 6.1.3.2) + activesupport (= 6.1.3.2) + marcel (~> 1.0.0) + mini_mime (~> 1.0.2) + activesupport (6.1.3.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + builder (3.2.4) + concurrent-ruby (1.1.8) + crass (1.0.6) diff-lcs (1.4.4) + erubi (1.10.0) + generator_spec (0.9.4) + activesupport (>= 3.0.0) + railties (>= 3.0.0) + globalid (0.4.2) + activesupport (>= 4.2.0) + i18n (1.8.10) + concurrent-ruby (~> 1.0) + loofah (2.9.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (1.0.1) + method_source (1.0.0) + mini_mime (1.0.3) + minitest (5.14.4) + nio4r (2.5.7) + nokogiri (1.11.3-x86_64-darwin) + racc (~> 1.4) + racc (1.5.2) + rack (2.2.3) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (6.1.3.2) + actioncable (= 6.1.3.2) + actionmailbox (= 6.1.3.2) + actionmailer (= 6.1.3.2) + actionpack (= 6.1.3.2) + actiontext (= 6.1.3.2) + actionview (= 6.1.3.2) + activejob (= 6.1.3.2) + activemodel (= 6.1.3.2) + activerecord (= 6.1.3.2) + activestorage (= 6.1.3.2) + activesupport (= 6.1.3.2) + bundler (>= 1.15.0) + railties (= 6.1.3.2) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (6.1.3.2) + actionpack (= 6.1.3.2) + activesupport (= 6.1.3.2) + method_source + rake (>= 0.8.7) + thor (~> 1.0) rake (12.3.3) rspec (3.10.0) rspec-core (~> 3.10.0) @@ -21,11 +133,27 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-support (3.10.2) + sprockets (4.0.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.2) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (1.1.0) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + websocket-driver (0.7.3) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.4.2) PLATFORMS ruby DEPENDENCIES + generator_spec + rails (~> 6.1.0) rake (~> 12.0) rspec (~> 3.0) sp-rails-saml! diff --git a/README.md b/README.md index 7a72843..722211c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # SpRailsSaml -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sp_rails_saml`. To experiment with that code, run `bin/console` for an interactive prompt. +Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sp-rails-saml`. To experiment with that code, run `bin/console` for an interactive prompt. TODO: Delete this and the text above, and describe your gem diff --git a/bin/console b/bin/console index acb178c..016ca06 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require "bundler/setup" -require "sp_rails_saml" +require "sp-rails-saml" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. diff --git a/lib/generators/sp-rails-saml/config_generator.rb b/lib/generators/sp-rails-saml/config_generator.rb new file mode 100644 index 0000000..a155358 --- /dev/null +++ b/lib/generators/sp-rails-saml/config_generator.rb @@ -0,0 +1,26 @@ +require 'rails/generators' + +module SpRailsSaml + class ConfigGenerator < Rails::Generators::Base + + desc "config/initializersにイニシャライザファイルを作成します" + + def create_initializer_file + create_file "config/initializers/sp-rails-saml.rb", default_initializer + end + + private + + def default_initializer +<<-EOS +SpRailsSaml::Settings.setup do |config| + config.sp_entity_id = '' + config.name_identifier_format = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' + config.authn_context = 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509' + config.authn_context_comparison = 'exact' + config.assertion_consumer_service_url = '' +end +EOS + end + end +end diff --git a/lib/sp-rails-saml.rb b/lib/sp-rails-saml.rb new file mode 100644 index 0000000..00d65e5 --- /dev/null +++ b/lib/sp-rails-saml.rb @@ -0,0 +1,7 @@ +require "active_support" +require 'sp-rails-saml/settings' +require 'generators/sp-rails-saml/config_generator' + +module SpRailsSaml + class Error < StandardError; end +end diff --git a/lib/sp_rails_saml/settings.rb b/lib/sp-rails-saml/settings.rb similarity index 81% rename from lib/sp_rails_saml/settings.rb rename to lib/sp-rails-saml/settings.rb index 73a0b8b..9a683b0 100644 --- a/lib/sp_rails_saml/settings.rb +++ b/lib/sp-rails-saml/settings.rb @@ -5,10 +5,7 @@ class << self attr_accessor :name_identifier_format attr_accessor :authn_context attr_accessor :authn_context_comparison - attr_accessor :idp_sso_service_url attr_accessor :assertion_consumer_service_url - attr_accessor :idp_cert - attr_accessor :idp_entity_id def setup(options = {}) options.each do |key, value| diff --git a/lib/sp_rails_saml/version.rb b/lib/sp-rails-saml/version.rb similarity index 100% rename from lib/sp_rails_saml/version.rb rename to lib/sp-rails-saml/version.rb diff --git a/lib/sp_rails_saml.rb b/lib/sp_rails_saml.rb deleted file mode 100644 index 8b067df..0000000 --- a/lib/sp_rails_saml.rb +++ /dev/null @@ -1,6 +0,0 @@ -require "sp_rails_saml/version" -require 'sp_rails_saml/settings' - -module SpRailsSaml - class Error < StandardError; end -end diff --git a/sp-rails-saml.gemspec b/sp-rails-saml.gemspec index 4792b70..edbb750 100644 --- a/sp-rails-saml.gemspec +++ b/sp-rails-saml.gemspec @@ -1,4 +1,5 @@ -require_relative 'lib/sp_rails_saml/version' +$LOAD_PATH.push File.expand_path('../lib', __FILE__) +require 'sp-rails-saml/version' Gem::Specification.new do |spec| spec.name = "sp-rails-saml" diff --git a/spec/generators/sp_rails_saml/settings_generator_spec.rb b/spec/generators/sp_rails_saml/settings_generator_spec.rb new file mode 100644 index 0000000..5ea90fe --- /dev/null +++ b/spec/generators/sp_rails_saml/settings_generator_spec.rb @@ -0,0 +1,24 @@ +RSpec.describe SpRailsSaml::ConfigGenerator, type: :generator do + destination File.expand_path("../../../../tmp", __FILE__) + + before(:all) do + prepare_destination + run_generator + end + + let(:initializer_text) do +<<-EOS +SpRailsSaml::Settings.setup do |config| + config.sp_entity_id = '' + config.name_identifier_format = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' + config.authn_context = 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509' + config.authn_context_comparison = 'exact' + config.assertion_consumer_service_url = '' +end +EOS + end + + it "should create saml_settings initializer file" do + assert_file "config/initializers/sp-rails-saml.rb", initializer_text + end +end \ No newline at end of file diff --git a/spec/sp_rails_saml/settings_spec.rb b/spec/sp_rails_saml/settings_spec.rb index f791f80..8b15890 100644 --- a/spec/sp_rails_saml/settings_spec.rb +++ b/spec/sp_rails_saml/settings_spec.rb @@ -4,10 +4,7 @@ let(:name_identifier_format) { 'name_identifier_format' } let(:authn_context) { 'authn_context' } let(:authn_context_comparison) { 'authn_context_comparison' } - let(:idp_sso_service_url) { 'idp_sso_service_url' } let(:assertion_consumer_service_url) { 'assertion_consumer_service_url' } - let(:idp_cert) { 'idp_cert' } - let(:idp_entity_id) { 'idp_entity_id' } it 'should set settings value' do SpRailsSaml::Settings.setup do |config| @@ -15,20 +12,14 @@ config.name_identifier_format = name_identifier_format config.authn_context = authn_context config.authn_context_comparison = authn_context_comparison - config.idp_sso_service_url = idp_sso_service_url config.assertion_consumer_service_url = assertion_consumer_service_url - config.idp_cert = idp_cert - config.idp_entity_id = idp_entity_id end expect(SpRailsSaml::Settings.sp_entity_id).to eq sp_entity_id expect(SpRailsSaml::Settings.name_identifier_format).to eq name_identifier_format expect(SpRailsSaml::Settings.authn_context).to eq authn_context expect(SpRailsSaml::Settings.authn_context_comparison).to eq authn_context_comparison - expect(SpRailsSaml::Settings.idp_sso_service_url).to eq idp_sso_service_url expect(SpRailsSaml::Settings.assertion_consumer_service_url).to eq assertion_consumer_service_url - expect(SpRailsSaml::Settings.idp_cert).to eq idp_cert - expect(SpRailsSaml::Settings.idp_entity_id).to eq idp_entity_id end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2122666..14d5d2d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ require "bundler/setup" -require "sp_rails_saml" +require "sp-rails-saml" +require "generator_spec" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure