diff --git a/Gemfile.lock b/Gemfile.lock index c56de6bf..d4992a1c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,7 +50,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 4834399048b8c9cff4882d435f770826930665f6 + revision: 48366d360d910ea038850249e1361f831b3dc6dd specs: travis-core (0.0.1) actionmailer (~> 3.2.19) diff --git a/lib/travis/api/v3/models/user.rb b/lib/travis/api/v3/models/user.rb index 874bc908..4ba4d7f8 100644 --- a/lib/travis/api/v3/models/user.rb +++ b/lib/travis/api/v3/models/user.rb @@ -7,7 +7,6 @@ module Travis::API::V3 has_many :repositories, through: :permissions has_many :organizations, through: :memberships - serialize :github_oauth_token, Extensions::EncryptedColumn.new(disable: true) def token diff --git a/lib/travis/api/v3/queries/organization.rb b/lib/travis/api/v3/queries/organization.rb index fed17682..218be855 100644 --- a/lib/travis/api/v3/queries/organization.rb +++ b/lib/travis/api/v3/queries/organization.rb @@ -3,8 +3,8 @@ module Travis::API::V3 params :id, :login def find - return Models::Organization.find_by_id(id) if id - return Models::Organization.find_by_login(login) if login + return Models::Organization.find_by_id(id) if id + return Models::Organization.where('lower(login) = ?'.freeze, login.downcase).first if login raise WrongParams, 'missing organization.id or organization.login'.freeze end end diff --git a/lib/travis/api/v3/queries/user.rb b/lib/travis/api/v3/queries/user.rb index c05c9899..f3ddb631 100644 --- a/lib/travis/api/v3/queries/user.rb +++ b/lib/travis/api/v3/queries/user.rb @@ -3,8 +3,8 @@ module Travis::API::V3 params :id, :login def find - return Models::User.find_by_id(id) if id - return Models::User.find_by_login(login) if login + return Models::User.find_by_id(id) if id + return Models::User.where('lower(login) = ?'.freeze, login.downcase).first if login raise WrongParams, 'missing user.id or user.login'.freeze end end diff --git a/spec/v3/services/account/find_spec.rb b/spec/v3/services/account/find_spec.rb index a114efd0..644311a1 100644 --- a/spec/v3/services/account/find_spec.rb +++ b/spec/v3/services/account/find_spec.rb @@ -19,6 +19,19 @@ describe Travis::API::V3::Services::Account::Find do }} end + describe 'it is not case sensitive' do + before { get("/v3/account/example-ORG") } + example { expect(last_response).to be_ok } + example { expect(JSON.load(body)).to be == { + "@type" => "organization", + "@href" => "/v3/org/#{org.id}", + "id" => org.id, + "login" => "example-org", + "name" => nil, + "github_id" => nil + }} + end + describe "does not allow overriding org id" do let(:other) { Organization.new(login: 'other-org') } before { other.save! } @@ -57,6 +70,21 @@ describe Travis::API::V3::Services::Account::Find do }} end + describe 'it is not case sensitive' do + before { get("/v3/account/example-USER") } + example { expect(last_response).to be_ok } + example { expect(JSON.load(body)).to be == { + "@type" => "user", + "@href" => "/v3/user/#{user.id}", + "id" => user.id, + "login" => "example-user", + "name" => nil, + "github_id" => nil, + "is_syncing"=> nil, + "synced_at" => nil + }} + end + describe "does not allow overriding user id" do let(:other) { User.new(login: 'other-user') } before { other.save! }