Added support for https database URIs.

Signed-off-by: Tapajós <tapajos@gmail.com>
This commit is contained in:
Mathias Meyer 2009-09-28 20:28:33 +08:00 committed by Matt Aimonetti
parent 2f2c507582
commit d8e7652680
2 changed files with 51 additions and 5 deletions

View file

@ -96,14 +96,14 @@ module CouchRest
def parse url def parse url
case url case url
when /^http:\/\/(.*)\/(.*)\/(.*)/ when /^https?:\/\/(.*)\/(.*)\/(.*)/
host = $1 host = $1
db = $2 db = $2
docid = $3 docid = $3
when /^http:\/\/(.*)\/(.*)/ when /^https?:\/\/(.*)\/(.*)/
host = $1 host = $1
db = $2 db = $2
when /^http:\/\/(.*)/ when /^https?:\/\/(.*)/
host = $1 host = $1
when /(.*)\/(.*)\/(.*)/ when /(.*)\/(.*)\/(.*)/
host = $1 host = $1

View file

@ -54,7 +54,7 @@ describe CouchRest do
db[:host].should == "127.0.0.1" db[:host].should == "127.0.0.1"
end end
it "should parse a host and db with http" do it "should parse a host and db with http" do
db = CouchRest.parse "http://127.0.0.1/my-db" db = CouchRest.parse "https://127.0.0.1/my-db"
db[:database].should == "my-db" db[:database].should == "my-db"
db[:host].should == "127.0.0.1" db[:host].should == "127.0.0.1"
end end
@ -68,16 +68,31 @@ describe CouchRest do
db[:database].should == "my-db" db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555" db[:host].should == "127.0.0.1:5555"
end end
it "should parse a host with a port and db with https" do
db = CouchRest.parse "https://127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
end
it "should parse just a host" do it "should parse just a host" do
db = CouchRest.parse "http://127.0.0.1:5555/" db = CouchRest.parse "http://127.0.0.1:5555/"
db[:database].should be_nil db[:database].should be_nil
db[:host].should == "127.0.0.1:5555" db[:host].should == "127.0.0.1:5555"
end end
it "should parse just a host with https" do
db = CouchRest.parse "https://127.0.0.1:5555/"
db[:database].should be_nil
db[:host].should == "127.0.0.1:5555"
end
it "should parse just a host no slash" do it "should parse just a host no slash" do
db = CouchRest.parse "http://127.0.0.1:5555" db = CouchRest.parse "http://127.0.0.1:5555"
db[:host].should == "127.0.0.1:5555" db[:host].should == "127.0.0.1:5555"
db[:database].should be_nil db[:database].should be_nil
end end
it "should parse just a host no slash and https" do
db = CouchRest.parse "https://127.0.0.1:5555"
db[:host].should == "127.0.0.1:5555"
db[:database].should be_nil
end
it "should get docid" do it "should get docid" do
db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc" db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db" db[:database].should == "my-db"
@ -90,7 +105,12 @@ describe CouchRest do
db[:host].should == "127.0.0.1:5555" db[:host].should == "127.0.0.1:5555"
db[:doc].should == "my-doc" db[:doc].should == "my-doc"
end end
it "should get docid with https" do
db = CouchRest.parse "https://127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:doc].should == "my-doc"
end
it "should parse a host and db" do it "should parse a host and db" do
db = CouchRest.parse "127.0.0.1/my-db" db = CouchRest.parse "127.0.0.1/my-db"
db[:database].should == "my-db" db[:database].should == "my-db"
@ -101,6 +121,11 @@ describe CouchRest do
db[:database].should == "my-db" db[:database].should == "my-db"
db[:host].should == "127.0.0.1" db[:host].should == "127.0.0.1"
end end
it "should parse a host and db with https" do
db = CouchRest.parse "https://127.0.0.1/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1"
end
it "should parse a host with a port and db" do it "should parse a host with a port and db" do
db = CouchRest.parse "127.0.0.1:5555/my-db" db = CouchRest.parse "127.0.0.1:5555/my-db"
db[:database].should == "my-db" db[:database].should == "my-db"
@ -111,16 +136,31 @@ describe CouchRest do
db[:database].should == "my-db" db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555" db[:host].should == "127.0.0.1:5555"
end end
it "should parse a host with a port and db with https" do
db = CouchRest.parse "http://127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
end
it "should parse just a host" do it "should parse just a host" do
db = CouchRest.parse "http://127.0.0.1:5555/" db = CouchRest.parse "http://127.0.0.1:5555/"
db[:database].should be_nil db[:database].should be_nil
db[:host].should == "127.0.0.1:5555" db[:host].should == "127.0.0.1:5555"
end end
it "should parse just a host with https" do
db = CouchRest.parse "https://127.0.0.1:5555/"
db[:database].should be_nil
db[:host].should == "127.0.0.1:5555"
end
it "should parse just a host no slash" do it "should parse just a host no slash" do
db = CouchRest.parse "http://127.0.0.1:5555" db = CouchRest.parse "http://127.0.0.1:5555"
db[:host].should == "127.0.0.1:5555" db[:host].should == "127.0.0.1:5555"
db[:database].should be_nil db[:database].should be_nil
end end
it "should parse just a host no slash and https" do
db = CouchRest.parse "https://127.0.0.1:5555"
db[:host].should == "127.0.0.1:5555"
db[:database].should be_nil
end
it "should get docid" do it "should get docid" do
db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc" db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db" db[:database].should == "my-db"
@ -133,6 +173,12 @@ describe CouchRest do
db[:host].should == "127.0.0.1:5555" db[:host].should == "127.0.0.1:5555"
db[:doc].should == "my-doc" db[:doc].should == "my-doc"
end end
it "should get docid with https" do
db = CouchRest.parse "https://127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "127.0.0.1:5555"
db[:doc].should == "my-doc"
end
end end
describe "easy initializing a database adapter" do describe "easy initializing a database adapter" do