Fix remaining remarks

This commit is contained in:
theworldbright 2016-01-04 16:26:00 +09:00
parent ef7ea1a855
commit 58aef5658b
8 changed files with 65 additions and 58 deletions

View file

@ -97,7 +97,7 @@ module Api
if seconds.nil? if seconds.nil?
false false
else else
(Time.zone.now.utc.to_i - current_user.current_sign_in_at.to_i) > seconds.to_i (Time.now - current_user.current_sign_in_at) > seconds.to_i
end end
end end

View file

@ -55,7 +55,6 @@ module Api
logger.info e.backtrace[0, 10].join("\n") logger.info e.backtrace[0, 10].join("\n")
render json: {error: :invalid_grant, error_description: e.message, status: 400} render json: {error: :invalid_grant, error_description: e.message, status: 400}
end end
end end
end end
end end

View file

@ -76,13 +76,14 @@ module Api
supported_metadata.each_with_object({}) do |key, attr| supported_metadata.each_with_object({}) do |key, attr|
value = registrar.public_send(key) value = registrar.public_send(key)
next unless value next unless value
if key == :subject_type case key
when :subject_type
attr[:ppid] = (value == "pairwise") attr[:ppid] = (value == "pairwise")
elsif key == :jwks_uri when :jwks_uri
response = Faraday.get(value) response = Faraday.get(value)
attr[:jwks] = response.body attr[:jwks] = response.body
attr[:jwks_uri] = value attr[:jwks_uri] = value
elsif key == :jwks when :jwks
attr[:jwks] = value.to_json attr[:jwks] = value.to_json
else else
attr[key] = value attr[key] = value

View file

@ -1,11 +1,11 @@
Rails.application.config.middleware.insert 0, Rack::Cors do Rails.application.config.middleware.insert 0, Rack::Cors do
allow do allow do
origins "*" origins "*"
resource "/.well-known/host-meta"
resource "/webfinger"
resource "/.well-known/webfinger"
resource "/.well-known/openid-configuration"
resource "/api/openid_connect/user_info", methods: %i(get post) resource "/api/openid_connect/user_info", methods: %i(get post)
resource "/api/v0/*", methods: %i(delete get post) resource "/api/v0/*", methods: %i(delete get post)
resource "/.well-known/host-meta"
resource "/.well-known/webfinger"
resource "/.well-known/openid-configuration"
resource "/webfinger"
end end
end end

View file

@ -919,8 +919,8 @@ en:
description: "This allows the application to send new posts, write conversations, and send reactions" description: "This allows the application to send new posts, write conversations, and send reactions"
error_page: error_page:
title: "Oh! Something went wrong :(" title: "Oh! Something went wrong :("
contact_developer: "You should contact the developer of the application and include the following detailed message error:" contact_developer: "You should contact the developer of the application and include the following detailed error message:"
login_required: "You must first login before authorize this application" login_required: "You must first login before you can authorize this application"
could_not_authorize: "The application could not be authorized" could_not_authorize: "The application could not be authorized"
people: people:

View file

@ -35,5 +35,5 @@ Then /^I should receive an "([^\"]*)" error$/ do |error_message|
end end
Then(/^I should see a message containing "(.*?)"$/) do |message| Then(/^I should see a message containing "(.*?)"$/) do |message|
expect(find("#openid_connect_error_description").text).to eq(message) expect(find("#openid_connect_error_description").text).to include(message)
end end

View file

@ -356,7 +356,7 @@ describe Api::OpenidConnect::AuthorizationsController, type: :controller do
it "raises an error" do it "raises an error" do
delete :destroy, id: 123_456_789 delete :destroy, id: 123_456_789
expect(response).to redirect_to(api_openid_connect_user_applications_url) expect(response).to redirect_to(api_openid_connect_user_applications_url)
expect(flash[:error]).to eq("The attempt to revoke the authorization with ID 123456789 has failed") expect(flash[:error]).to eq("The attempt to revoke the authorization with ID 123456789 failed")
end end
end end
end end

View file

@ -5,8 +5,11 @@ describe Api::OpenidConnect::ClientsController, type: :controller do
context "when valid parameters are passed" do context "when valid parameters are passed" do
it "should return a client id" do it "should return a client id" do
stub_request(:get, "http://example.com/uris") stub_request(:get, "http://example.com/uris")
.with(headers: {"Accept" => "*/*", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", .with(headers: {
"User-Agent" => "Faraday v0.9.2"}) "Accept" => "*/*",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"User-Agent" => "Faraday v0.9.2"
})
.to_return(status: 200, body: "[\"http://localhost\"]", headers: {}) .to_return(status: 200, body: "[\"http://localhost\"]", headers: {})
post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client", post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client",
response_types: [], grant_types: [], application_type: "web", contacts: [], response_types: [], grant_types: [], application_type: "web", contacts: [],
@ -22,7 +25,9 @@ describe Api::OpenidConnect::ClientsController, type: :controller do
context "when valid parameters with jwks is passed" do context "when valid parameters with jwks is passed" do
it "should return a client id" do it "should return a client id" do
stub_request(:get, "http://example.com/uris") stub_request(:get, "http://example.com/uris")
.with(headers: {"Accept" => "*/*", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", .with(headers: {
"Accept" => "*/*",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"User-Agent" => "Faraday v0.9.2"}) "User-Agent" => "Faraday v0.9.2"})
.to_return(status: 200, body: "[\"http://localhost\"]", headers: {}) .to_return(status: 200, body: "[\"http://localhost\"]", headers: {})
post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client", post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client",
@ -80,11 +85,13 @@ describe Api::OpenidConnect::ClientsController, type: :controller do
context "when valid parameters with jwks_uri is passed" do context "when valid parameters with jwks_uri is passed" do
it "should return a client id" do it "should return a client id" do
stub_request(:get, "http://example.com/uris") stub_request(:get, "http://example.com/uris")
.with(headers: {"Accept" => "*/*", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", .with(headers: {"Accept" => "*/*",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"User-Agent" => "Faraday v0.9.2"}) "User-Agent" => "Faraday v0.9.2"})
.to_return(status: 200, body: "[\"http://localhost\"]", headers: {}) .to_return(status: 200, body: "[\"http://localhost\"]", headers: {})
stub_request(:get, "https://kentshikama.com/api/openid_connect/jwks.json") stub_request(:get, "https://kentshikama.com/api/openid_connect/jwks.json")
.with(headers: {"Accept" => "*/*", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", .with(headers: {"Accept" => "*/*",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"User-Agent" => "Faraday v0.9.2"}) "User-Agent" => "Faraday v0.9.2"})
.to_return(status: 200, .to_return(status: 200,
body: "{\"keys\":[{\"kty\":\"RSA\",\"e\":\"AQAB\",\"n\":\"qpW\",\"use\":\"sig\"}]}", headers: {}) body: "{\"keys\":[{\"kty\":\"RSA\",\"e\":\"AQAB\",\"n\":\"qpW\",\"use\":\"sig\"}]}", headers: {})