This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#54137341]
- Loading branch information
Cornelia Davis, Jeff Schnitzer and alex choi
committed
Sep 24, 2013
1 parent
6ae70bc
commit 853054c
Showing
12 changed files
with
188 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
class AppSettings < Settingslogic | ||
# This points at /var/vcap/packages, not /var/vcap/jobs which is where | ||
# BOSH renders the config templates. | ||
#source Rails.root.join("config/app_settings.yml") | ||
|
||
source '/var/vcap/jobs/cf-mysql-broker/config/app_settings.yml' | ||
case ENV['RAILS_ENV'] | ||
when 'production' | ||
source Rails.root.join("config/app_settings_production.yml") | ||
when 'test' | ||
source Rails.root.join("config/app_settings_test.yml") | ||
else | ||
source Rails.root.join("config/app_settings_development.yml") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
database: | ||
admin_user: root | ||
admin_password: password | ||
singleton_database: development | ||
ip: localhost | ||
port: 3306 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
database: | ||
admin_user: root | ||
admin_password: password | ||
singleton_database: test | ||
ip: localhost | ||
port: 3306 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
development: | ||
adapter: mysql2 | ||
encoding: utf8 | ||
database: development | ||
pool: 5 | ||
username: root | ||
password: password | ||
|
||
|
||
# Warning: The database defined as "test" will be erased and | ||
# re-generated from your development database when you run "rake". | ||
# Do not set this db to the same as development or production. | ||
test: | ||
adapter: mysql2 | ||
encoding: utf8 | ||
database: test | ||
pool: 5 | ||
username: root | ||
password: password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# encoding: UTF-8 | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(version: 0) do | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'securerandom' | ||
require 'digest/md5' | ||
|
||
class UserCreds | ||
attr_reader :username, :password | ||
|
||
def initialize(guid) | ||
# mysql usernames are limited to 16 chars | ||
@username = Digest::MD5.base64digest(guid)[0...16] | ||
@password = SecureRandom.hex(8) | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'spec_helper' | ||
|
||
|
||
def cleanup_mysql_user(username) | ||
ActiveRecord::Base.connection.execute("DROP USER #{username}") | ||
rescue | ||
end | ||
|
||
|
||
describe 'POST /v2/service_bindings' do | ||
let(:instance_guid) { 'INSTANCE-1' } | ||
let(:binding_guid) { 'BINDING-1' } | ||
let(:password) { 'somepassword' } | ||
let(:username) { UserCreds.new(binding_guid).username } | ||
|
||
before do | ||
SecureRandom.stub(:hex).with(8).and_return(password) | ||
|
||
cleanup_mysql_user(username) | ||
end | ||
|
||
after do | ||
cleanup_mysql_user(username) | ||
end | ||
|
||
it 'creates a user and returns the new service binding' do | ||
put "/v2/service_instances/#{instance_guid}", {service_plan_id: 'PLAN-1'}, env | ||
put "/v2/service_bindings/#{binding_guid}", {service_instance_id: instance_guid}, env | ||
|
||
expect(response.status).to eq(201) | ||
instance = JSON.parse(response.body) | ||
|
||
expect(instance.fetch('credentials')).to eq({ | ||
'hostname' => 'localhost', | ||
'name' => 'test', | ||
'username' => username, | ||
'password' => password, | ||
'port' => 3306, | ||
'jdbcUrl' => "jdbc:mysql://#{username}:#{password}@localhost:3306/test", | ||
'uri' => "mysql://#{username}:#{password}@localhost:3306/test?reconnect=true", | ||
}) | ||
|
||
client = Mysql2::Client.new( | ||
:host => AppSettings.database.ip, | ||
:port => AppSettings.database.port, | ||
:database => AppSettings.database.singleton_database, | ||
:username => username, | ||
:password => password, | ||
) | ||
|
||
client.query("CREATE TABLE IF NOT EXISTS data_values ( id VARCHAR(20), data_value VARCHAR(20));") | ||
client.query("INSERT INTO data_values VALUES('123', '456');") | ||
found = client.query("SELECT id, data_value FROM data_values;").first | ||
expect(found.fetch('data_value')).to eq('456') | ||
end | ||
end |