Skip to content

Commit

Permalink
Origin UI 72 - Memberhip
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Sep 26, 2013
1 parent a887e9c commit 9ed27fc
Show file tree
Hide file tree
Showing 95 changed files with 2,284 additions and 663 deletions.
384 changes: 260 additions & 124 deletions autocomplete/rhc_bash

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions features/README.md → cucumber/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
DEPRECATED
=========
Cucumber is being phased out - please add RSpec style features to the features/* directory

Overview
==============

Expand All @@ -14,7 +18,7 @@ Usage
Run from the base directory with

```
<env variables> bundle exec rake features
<env variables> bundle exec rake cucummber
```

At the very least, you will probably want to specify `RHC_SERVER` (or
Expand Down Expand Up @@ -46,7 +50,7 @@ proxy. For instance:

GIT_SSH
-------
This is automatically set in `features/support/env.rb` but can be
This is automatically set in `cucumber/support/env.rb` but can be
overridden if desired.

This environment variable will be used by any `git` or `ssh` commands.
Expand Down Expand Up @@ -110,7 +114,7 @@ reporting.
To run the test, simply run

```
<env variables> bundle exec rake features
<env variables> bundle exec rake cucumber
```

1. Running the tests directly via `cucumber` gives you some more
Expand All @@ -122,9 +126,9 @@ here](https://github.com/cucumber/cucumber/wiki/Running-Features).
```
# This runs all scenarios with the @application tag that also do not
# have the @init tag
cucumber features -t @application -t ~@init
cucumber cucumber -t @application -t ~@init
# This runs the scenario starting at a specific line in the file
cucumber features/application.feature:42
cucumber cucumber/application.feature:42
```

Developing tests
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
141 changes: 141 additions & 0 deletions features/core_feature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
require 'spec_helper'
require 'direct_execution_helper'

describe "rhc core scenarios" do

it "reports a version" do
r = rhc '--version'
r.status.should == 0
r.stdout.should match /rhc \d+\.\d+\.\d+\b/
end

it "displays help" do
r = rhc 'help'
r.status.should == 0
r.stdout.should match "Command line interface for OpenShift"
r.stdout.should match "Usage: rhc"
r.stdout.should match "Getting started"
r.stdout.should match "See 'rhc help options' for a list"
end

context "with a clean configuration" do
before{ use_clean_config }

it "walks through a configuration" do
r = rhc :setup, :with => setup_args
r.stdout.should match 'OpenShift Client Tools'
r.stdout.should match 'Checking for git ...'
r.stdout.should match 'Checking for applications ...'
r.stdout.should match 'Your client tools are now configured.'
r.status.should == 0

r = rhc :account
r.stdout.should match "on #{ENV['RHC_SERVER']}"
r.stdout.should match 'Gears'
r.stdout.should match 'Plan'
end

it "starts the wizard on default invocation" do
r = rhc
r.stdout.should match "OpenShift Client Tools"
end
end

context "when creating an app" do
when_running 'create-app', 'test1', a_web_cartridge
before{ no_applications(/^test1/) }
it "returns the proper info and is in the rest api" do
status.should == 0
output.should match "Your application 'test1' is now available"
output.should match /Gear Size: .*default/
output.should match /Scaling: .*no/
output.should match %r(URL: .*http://test1-)
output.should match "Cloned to"

apps = client.applications
apps.should_not be_empty
apps.should include{ |app| app.name == 'test1' }
end
end

context "with an existing app" do
before(:all) do
standard_config
@app = has_an_application
end

let(:app){ @app }

it "should show app state" do
r = rhc 'app-show', app.name, '--state'
r.status.should == 0
r.stdout.should match "Cartridge #{a_web_cartridge} is started"
end

it "should stop and start the app" do
r = rhc 'stop-app', app.name
r.status.should == 0
r.stdout.should match "#{app.name} stopped"
r = rhc 'start-app', app.name
r.status.should == 0
r.stdout.should match "#{app.name} started"
end

it "should show gear status" do
r = rhc 'app-show', app.name, '--gears'
r.status.should == 0
r.stdout.lines.to_a.length.should == 3
r.stdout.should match app.ssh_string
app.cartridges.map(&:name).each do |c|
r.stdout.should match c
end
r.stdout.should match "started"
end

it "should show gear ssh strings" do
r = rhc 'app-show', app.name, '--gears', 'ssh'
r.status.should == 0
r.stdout.lines.to_a.length.should == 1
r.stdout.chomp.should == app.ssh_string
end

context "when the app is cloned" do
before(:all) do
rhc('git-clone', @app.name).status.should == 0
Dir.exists?(@app.name).should be_true
Dir.chdir @app.name
end
let(:git_config){ `git config --list` }

it "will set Git config values" do
git_config.should match "rhc.app-id=#{app.id}"
git_config.should match "rhc.app-name=#{app.name}"
git_config.should match "rhc.domain-name=#{app.domain_name}"
end

it "will infer the current app from the git repository" do
r = rhc 'show-app'
r.stdout.should match app.name
r.stdout.should match app.uuid
r.stdout.should match app.ssh_string
r.stdout.should match app.app_url
(app.cartridges.map(&:name) + app.cartridges.map(&:display_name)).each{ |n| r.stdout.should match n }
r.status.should == 0
end

it "will fetch the quotas from the app" do
r = rhc 'show-app', '--gears', 'quota'
r.stdout.chomp.lines.count.should == (app.gear_count + 2)
app.cartridges.map(&:name).each{ |n| r.stdout.should match n }
app.cartridges.map(&:gear_storage).each{ |n| r.stdout.should match(RHC::Helpers.human_size(n)) }
r.status.should == 0
end

it "will ssh to the app and run a command" do
r = rhc 'ssh', '--ssh', ENV['GIT_SSH'], 'echo $OPENSHIFT_APP_NAME'
r.stdout.should match app.name
r.status.should == 0
end
end
end
end
45 changes: 45 additions & 0 deletions features/domains_feature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'spec_helper'
require 'direct_execution_helper'

describe "rhc domain scenarios" do
context "with an existing domain" do
before(:all) do
standard_config
@domain = has_a_domain
end
let(:domain){ @domain }

it "should display the domain configuration" do
r = rhc 'configure-domain', domain.id
r.status.should == 0
r.stdout.should match "Allowed Gear Sizes:\s+#{domain.allowed_gear_sizes.join(", ")}"
end

it "should change the domain configuration" do
r = rhc 'configure-domain', domain.id, '--no-allowed-gear-sizes'
r.status.should == 0
r.stdout.should match "Allowed Gear Sizes:\s+<none>$"
client.reset.find_domain(domain.id).allowed_gear_sizes.should == []

all_sizes = client.user.capabilities.gear_sizes
r = rhc 'configure-domain', domain.id, '--allowed-gear-sizes', all_sizes.join(',')
r.status.should == 0
r.stdout.should match "Allowed Gear Sizes:\s+#{all_sizes.join(', ')}$"
client.reset.find_domain(domain.id).allowed_gear_sizes.should == all_sizes
end

it "should reject invalid gear size configuration changes" do
all_sizes = client.user.capabilities.gear_sizes

r = rhc 'configure-domain', domain.id, '--allowed-gear-sizes', '_not_a_size_'
r.status.should_not == 1
r.stdout.should match "Updating domain configuration.*The following gear sizes are invalid: _not_a_size_"
client.reset.find_domain(domain.id).allowed_gear_sizes.should == all_sizes

r = rhc 'configure-domain', domain.id, '--allowed-gear-sizes'
r.status.should_not == 1
r.stdout.should match "invalid option: Provide a comma delimited .* --allowed-gear-sizes"
client.reset.find_domain(domain.id).allowed_gear_sizes.should == all_sizes
end
end
end
131 changes: 131 additions & 0 deletions features/members_feature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
require 'spec_helper'
require 'direct_execution_helper'

describe "rhc member scenarios" do
context "with an existing domain" do
before(:all) do
standard_config
@domain = has_a_domain
end

let(:domain){ @domain }

context "with no users" do
before{ no_members(domain) }

it "should not show members in the domain" do
r = rhc 'show-domain', domain.id
r.status.should == 0
r.stdout.should_not match "Members:"
r.stdout.should match "owned by #{domain.owner}"
end

it "should prevent leaving the domain for the owner" do
r = rhc 'leave-domain', domain.id
r.status.should_not == 1
r.stdout.should match "Leaving domain.*You are the owner of this domain and cannot leave"
end

it "should add and remove a member" do
user = other_users.keys.take(1).first
r = rhc 'add-member', user, '-n', domain.id
r.status.should == 0
r.stdout.should match "Adding 1 editor to domain"
r.stdout.should match "done"
client.find_domain(domain.id).members.any?{ |m| m.id == other_users[user].id && m.editor? }.should be_true

r = rhc 'show-domain', domain.id
r.status.should == 0
r.stdout.should match "Members:"
r.stdout.should match "#{user} \\(edit\\)"

r = rhc 'remove-member', user, '-n', domain.id
r.status.should == 0
r.stdout.should match "Removing 1 member from domain"
client.find_domain(domain.id).members.none?{ |m| m.id == other_users[user].id }.should be_true
end

it "should add and remove two members" do
user1, user2 = other_users.keys.take(2)
r = rhc 'add-member', user1, user2, '-n', domain.id
r.status.should == 0
r.stdout.should match "Adding 2 editors to domain"
r.stdout.should match "done"
members = client.find_domain(domain.id).members
members.any?{ |m| m.id == other_users[user1].id && m.editor? }.should be_true
members.any?{ |m| m.id == other_users[user2].id && m.editor? }.should be_true

r = rhc 'show-domain', domain.id
r.status.should == 0
r.stdout.should match "Members:"
r.stdout.should match "#{user1} \\(edit\\)"
r.stdout.should match "#{user2} \\(edit\\)"

r = rhc 'remove-member', user1, user2, '-n', domain.id
r.status.should == 0
r.stdout.should match "Removing 2 members from domain"
client.find_domain(domain.id).members.none?{ |m| m.id == other_users[user1].id }.should be_true
client.find_domain(domain.id).members.none?{ |m| m.id == other_users[user2].id }.should be_true
end

it "should add a view and an admin member. and allow users to leave the domain" do
user1, user2 = other_users.keys.take(2)

r = rhc 'add-member', user1, '--role', 'admin', '-n', domain.id
r.status.should == 0
r.stdout.should match "Adding 1 administrator to domain"
r.stdout.should match "done"
client.find_domain(domain.id).members.any?{ |m| m.id == other_users[user1].id && m.admin? }.should be_true

r = rhc 'add-member', user2, '--role', 'view', '-n', domain.id
r.status.should == 0
r.stdout.should match "Adding 1 viewer to domain"
r.stdout.should match "done"
client.find_domain(domain.id).members.any?{ |m| m.id == other_users[user2].id && m.viewer? }.should be_true

r = rhc 'show-domain', domain.id
r.status.should == 0
r.stdout.should match "Members:"
r.stdout.should match "#{user1} \\(admin\\)"
r.stdout.should match "#{user2} \\(view\\)"

r = rhc 'leave-domain', domain.id, :as => other_users[user2]
r.status.should == 0
r.stdout.should match "Leaving domain.*done"
end

it "should remove all non owners" do
user1, user2 = other_users.keys.take(2)
r = rhc 'add-member', user1, user2, '-n', domain.id
r.status.should == 0
r.stdout.should match "Adding 2 editors to domain"
r.stdout.should match "done"
members = client.find_domain(domain.id).members
members.any?{ |m| m.id == other_users[user1].id && m.editor? }.should be_true
members.any?{ |m| m.id == other_users[user2].id && m.editor? }.should be_true

r = rhc 'remove-member', domain.id, '--all'
r.status.should == 0
r.stdout.should match "Removing all members from domain.*done"
members = client.find_domain(domain.id).members
members.select(&:owner).should == members
end

it "should reject a non-existent user" do
r = rhc 'add-member', 'not-a-user', '-n', domain.id
r.status.should_not == 1
r.stdout.should match "There is no account with login not-a-user."
client.find_domain(domain.id).members.length.should == 1
end

it "should add a user by id" do
user = other_users.values.take(1).first
r = rhc 'add-member', user.id, '--ids', '-n', domain.id
r.status.should == 0
r.stdout.should match "Adding 1 editor to domain"
r.stdout.should match "done"
client.find_domain(domain.id).members.any?{ |m| m.id == user.id && m.editor? }.should be_true
end
end
end
end
2 changes: 2 additions & 0 deletions lib/rhc/auth/token_store.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'base64'

module RHC::Auth
class TokenStore
def initialize(dir)
Expand Down
Loading

0 comments on commit 9ed27fc

Please sign in to comment.