Permalink
Browse files

Starting on the api keys

  • Loading branch information...
1 parent ad9e0d9 commit 4862b5b22363e28627123ff04553eba3d7b2717e @qrush qrush committed Jun 3, 2009
@@ -0,0 +1,5 @@
+class ApiKeysController < ApplicationController
+ def show
+ render :text => "LOL"
+ end
+end
View
@@ -1,10 +1,13 @@
ActionController::Routing::Routes.draw do |map|
map.resources :rubygems, :as => "gems", :collection => { :search => :get, :migrate => :get, :mine => :get }
- map.root :controller => "home", :action => "index"
+ map.resource :api_key, :only => :show
+
map.sign_up 'sign_up', :controller => 'clearance/users', :action => 'new'
map.sign_in 'sign_in', :controller => 'clearance/sessions', :action => 'new'
map.sign_out 'sign_out',
:controller => 'clearance/sessions',
:action => 'destroy',
:method => :delete
+
+ map.root :controller => "home", :action => "index"
end
@@ -0,0 +1,9 @@
+class AddApiKeyToUsers < ActiveRecord::Migration
+ def self.up
+ add_column :users, :api_key, :string
+ end
+
+ def self.down
+ remove_column :users, :api_key
+ end
+end
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090601115133) do
+ActiveRecord::Schema.define(:version => 20090603212455) do
create_table "dependencies", :force => true do |t|
t.string "name"
@@ -48,6 +48,7 @@
t.string "token", :limit => 128
t.datetime "token_expires_at"
t.boolean "email_confirmed", :default => false, :null => false
+ t.string "api_key"
end
add_index "users", ["email"], :name => "index_users_on_email"
View
@@ -1,21 +1,47 @@
+class Gem::StreamUI
+ def ask_for_password(message)
+ system "stty -echo"
+ password = ask(message)
+ system "stty echo"
+ password
+ end
+end
+
class Gem::Commands::UpgradeCommand < Gem::Command
def description
'Upgrade your gem source to Gemcutter'
end
+ def ask_for_password(message)
+ ui.ask_for_password(message)
+ end
+
def initialize
super 'upgrade', description
end
def execute
+ add_source
+ sign_in
+ end
+
+ def add_source
if Gem.sources.include?(URL)
- say("Gemcutter is already your primary gem source. Please use `gem downgrade` if you wish to no longer use Gemcutter.")
+ say "Gemcutter is already your primary gem source. Please use `gem downgrade` if you wish to no longer use Gemcutter."
else
say "Upgrading your primary gem source to gemcutter.org"
Gem.sources.unshift URL
Gem.configuration.write
end
end
+
+ def sign_in
+ say "Enter your Gemcutter credentials. Don't have an account yet? Create one at #{URL}/sign_up"
+
+ user = ask("Email: ")
+ password = ask_for_password("Password: ")
+ end
+
end
Gem::CommandManager.instance.register_command :upgrade
@@ -0,0 +1,29 @@
+require 'test_helper'
+
+class ApiKeysControllerTest < ActionController::TestCase
+ context "on GET to show with no credentials" do
+ setup do
+ get :show
+ end
+ should "deny access" do
+ assert_response 401
+ assert_match "HTTP Basic: Access denied.", @response.body
+ end
+ end
+
+ context "on GET to show with unconfirmed user" do
+ setup do
+ @user = Factory(:user)
+ @request.env["HTTP_AUTHORIZATION"] = "Basic " +
+ Base64::encode64("#{@user.email}:#{@user.password}")
+ get :show
+ end
+ should "deny access" do
+ assert_response 401
+ assert_match "HTTP Basic: Access denied.", @response.body
+ end
+ end
+
+ context "on GET to show with confirmed user" do
+ end
+end
View
@@ -40,6 +40,11 @@ class PluginTest < ActiveSupport::TestCase
context "upgrading" do
setup do
@command = Gem::Commands::UpgradeCommand.new
+ @email = "joeuser@gemcutter.org"
+ @password = "secret"
+ mock(@command).say("Enter your Gemcutter credentials. Don't have an account yet? Create one at #{URL}/sign_up")
+ mock(@command).ask("Email: ") { @email }
+ mock(@command).ask_for_password("Password: ") { @password }
end
should "add gemcutter as first source" do

0 comments on commit 4862b5b

Please sign in to comment.