Permalink
Browse files

Laid down the foundation by using `omniauth-facebook` as a guide to t…

…he structure of this gem and the old OmniAuth determining what needs to be tested.
  • Loading branch information...
1 parent 2345a66 commit 3781061ba2f212f9f49aa6b02cc8e4ede448b4f7 Derek Lindahl committed Dec 14, 2011
Showing with 276 additions and 4 deletions.
  1. +20 −0 .gitignore
  2. +55 −0 .rvmrc
  3. +4 −0 Gemfile
  4. +22 −0 LICENSE
  5. +25 −4 README.md
  6. +13 −0 Rakefile
  7. +1 −0 lib/omniauth-cas.rb
  8. +2 −0 lib/omniauth/cas.rb
  9. +5 −0 lib/omniauth/cas/version.rb
  10. +9 −0 lib/omniauth/strategies/cas.rb
  11. +22 −0 omniauth-cas.gemspec
  12. +92 −0 spec/omniauth/strategies/cas_spec.rb
  13. +6 −0 spec/spec_helper.rb
View
@@ -0,0 +1,20 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+
+# RSpec
+.rspec
View
55 .rvmrc
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+
+# This is an RVM Project .rvmrc file, used to automatically load the ruby
+# development environment upon cd'ing into the directory
+
+# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
+environment_id="ruby-1.9.2-p290@omniauth-cas"
+
+#
+# Uncomment following line if you want options to be set only for given project.
+#
+# PROJECT_JRUBY_OPTS=( --1.9 )
+
+#
+# First we attempt to load the desired environment directly from the environment
+# file. This is very fast and efficient compared to running through the entire
+# CLI and selector. If you want feedback on which environment was used then
+# insert the word 'use' after --create as this triggers verbose mode.
+#
+if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
+then
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
+
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
+ then
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
+ fi
+else
+ # If the environment file has not yet been created, use the RVM CLI to select.
+ if ! rvm --create use "$environment_id"
+ then
+ echo "Failed to create RVM environment '${environment_id}'."
+ return 1
+ fi
+fi
+
+#
+# If you use an RVM gemset file to install a list of gems (*.gems), you can have
+# it be automatically loaded. Uncomment the following and adjust the filename if
+# necessary.
+#
+# filename=".gems"
+# if [[ -s "$filename" ]]
+# then
+# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
+# fi
+
+# If you use bundler, this might be useful to you:
+# if command -v bundle && [[ -s Gemfile ]]
+# then
+# bundle install
+# fi
+
+
View
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in omniauth-cas.gemspec
+gemspec
View
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2011 Derek Lindahl and CustomInk, LLC
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,8 +1,29 @@
-# OmniAuth CAS Strategy
+# Omniauth CAS Strategy [![Build Status](http://travis-ci.org/dlindahl/omniauth-cas.png?branch=master)](http://travis-ci.org/dlindahl/omniauth-cas)
-Please note that I really didn't want to have to write this, but I was forced too.
+TODO: Write a gem description
-So consider this an experiment for myself to learn CAS and OmniAuth.
+## Installation
-Use this at your own risk.
+Add this line to your application's Gemfile:
+ gem 'omniauth-cas'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install omniauth-cas
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
View
@@ -0,0 +1,13 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+
+require 'rspec/core/rake_task'
+desc 'Default: run specs.'
+task :default => :spec
+
+desc "Run specs"
+RSpec::Core::RakeTask.new
+
+task :test do
+ fail %q{This application uses RSpec. Try running "rake spec"}
+end
View
@@ -0,0 +1 @@
+require "omniauth/cas"
View
@@ -0,0 +1,2 @@
+require 'omniauth/cas/version'
+require 'omniauth/strategies/cas'
@@ -0,0 +1,5 @@
+module Omniauth
+ module Cas
+ VERSION = "0.0.1"
+ end
+end
@@ -0,0 +1,9 @@
+require 'omniauth/strategy'
+
+module OmniAuth
+ module Strategies
+ class Cas
+ include OmniAuth::Strategy
+ end
+ end
+end
View
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/omniauth/cas/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Derek Lindahl"]
+ gem.email = ["dlindahl@customink.com"]
+ # gem.description = %q{TODO: Write a gem description}
+ gem.summary = %q{CAS Strategy for OmniAuth}
+ gem.homepage = "https://github.com/dlindahl/omniauth-cas"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "omniauth-cas"
+ gem.require_paths = ["lib"]
+ gem.version = Omniauth::Cas::VERSION
+
+ gem.add_dependency 'omniauth', '~> 1.0'
+
+ gem.add_development_dependency 'rspec', '~> 2'
+ gem.add_development_dependency 'simplecov', '~> 0.5.4'
+end
@@ -0,0 +1,92 @@
+require File.expand_path( 'spec/spec_helper' )
+
+describe OmniAuth::Strategies::Cas, :type => :strategy do
+ # include OmniAuth::Test::StrategyTestCase
+
+ def strategy
+ # @cas_server ||= 'https://cas.example.org'
+ # [OmniAuth::Strategies::CAS, {:cas_server => @cas_server}]
+ end
+
+ describe 'GET /auth/cas' do
+ before do
+ # get '/auth/cas'
+ end
+
+ it 'should redirect to the CAS server'# do
+ # last_response.should be_redirect
+ # return_to = CGI.escape(last_request.url + '/callback')
+ # last_response.headers['Location'].should == @cas_server + '/login?service=' + return_to
+ # end
+ end
+
+ describe 'GET /auth/cas/callback without a ticket' do
+ before do
+ # get '/auth/cas/callback'
+ end
+ it 'should fail'# do
+ # last_response.should be_redirect
+ # last_response.headers['Location'].should =~ /no_ticket/
+ # end
+ end
+
+ describe 'GET /auth/cas/callback with an invalid ticket' do
+ before do
+ # stub_request(:get, /^https:\/\/cas.example.org(:443)?\/serviceValidate\?([^&]+&)?ticket=9391d/).
+ # to_return(:body => File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cas_failure.xml')))
+ # get '/auth/cas/callback?ticket=9391d'
+ end
+ it 'should fail'# do
+ # last_response.should be_redirect
+ # last_response.headers['Location'].should =~ /invalid_ticket/
+ # end
+ end
+
+ describe 'GET /auth/cas/callback with a valid ticket' do
+ before do
+ # stub_request(:get, /^https:\/\/cas.example.org(:443)?\/serviceValidate\?([^&]+&)?ticket=593af/).
+ # with { |request| @request_uri = request.uri.to_s }.
+ # to_return(:body => File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cas_success.xml')))
+ # get '/auth/cas/callback?ticket=593af'
+ end
+
+ it 'should strip the ticket parameter from the callback URL before sending it to the CAS server'# do
+ # @request_uri.scan('ticket=').length.should == 1
+ # end
+
+ # sets_an_auth_hash
+ # sets_provider_to 'cas'
+ # sets_uid_to 'psegel'
+
+ it 'should set additional user information'# do
+ # extra = (last_request.env['omniauth.auth'] || {})['extra']
+ # extra.should be_kind_of(Hash)
+ # extra['first-name'].should == 'Peter'
+ # extra['last-name'].should == 'Segel'
+ # extra['hire-date'].should == '2004-07-13'
+ # end
+
+ it 'should call through to the master app'# do
+ # last_response.body.should == 'true'
+ # end
+ end
+
+ # unless RUBY_VERSION =~ /^1\.8\.\d$/
+ # describe 'GET /auth/cas/callback with a valid ticket and gzipped response from the server on ruby >1.8' do
+ # before do
+ # zipped = StringIO.new
+ # Zlib::GzipWriter.wrap zipped do |io|
+ # io.write File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cas_success.xml'))
+ # end
+ # stub_request(:get, /^https:\/\/cas.example.org(:443)?\/serviceValidate\?([^&]+&)?ticket=593af/).
+ # with { |request| @request_uri = request.uri.to_s }.
+ # to_return(:body => zipped.string, :headers => { 'content-encoding' => 'gzip' })
+ # get '/auth/cas/callback?ticket=593af'
+ # end
+ #
+ # it 'should call through to the master app when response is gzipped' do
+ # last_response.body.should == 'true'
+ # end
+ # end
+ # end
+end
View
@@ -0,0 +1,6 @@
+require 'bundler/setup'
+
+require 'simplecov'
+SimpleCov.start
+
+require 'omniauth-cas'

0 comments on commit 3781061

Please sign in to comment.