Replace let!() with factory girl
This commit is contained in:
parent
b9da104b28
commit
6e1a673459
5 changed files with 58 additions and 44 deletions
|
|
@ -1,16 +1,8 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Api::OpenidConnect::AuthorizationsController, type: :controller do
|
||||
let!(:client) do
|
||||
Api::OpenidConnect::OAuthApplication.create!(
|
||||
client_name: "Diaspora Test Client", redirect_uris: ["http://localhost:3000/"])
|
||||
end
|
||||
let!(:client_with_multiple_redirects) do
|
||||
Api::OpenidConnect::OAuthApplication.create!(
|
||||
client_name: "Diaspora Test Client", redirect_uris: ["http://localhost:3000/", "http://localhost/"])
|
||||
end
|
||||
|
||||
# TODO: jhass - "Might want to setup some factories in spec/factories.rb, see factory_girl's docs."
|
||||
let!(:client) { FactoryGirl.create(:o_auth_application) }
|
||||
let!(:client_with_multiple_redirects) { FactoryGirl.create(:o_auth_application_with_multiple_redirects) }
|
||||
|
||||
before do
|
||||
sign_in :user, alice
|
||||
|
|
|
|||
|
|
@ -310,6 +310,54 @@ FactoryGirl.define do
|
|||
|
||||
factory(:status, :parent => :status_message)
|
||||
|
||||
factory :o_auth_application, class: Api::OpenidConnect::OAuthApplication do
|
||||
client_name "Diaspora Test Client"
|
||||
redirect_uris ["http://localhost:3000/"]
|
||||
end
|
||||
|
||||
factory :o_auth_application_with_ppid, class: Api::OpenidConnect::OAuthApplication do
|
||||
client_name "Diaspora Test Client"
|
||||
redirect_uris ["http://localhost:3000/"]
|
||||
ppid true
|
||||
sector_identifier_uri "https://example.com/uri"
|
||||
end
|
||||
|
||||
factory :o_auth_application_with_multiple_redirects, class: Api::OpenidConnect::OAuthApplication do
|
||||
client_name "Diaspora Test Client"
|
||||
redirect_uris ["http://localhost:3000/", "http://localhost/"]
|
||||
end
|
||||
|
||||
factory :auth_with_read, class: Api::OpenidConnect::Authorization do
|
||||
o_auth_application
|
||||
user
|
||||
|
||||
after(:create) do |auth_with_read|
|
||||
auth_with_read.scopes << [Api::OpenidConnect::Scope.find_or_create_by(name: "openid"),
|
||||
Api::OpenidConnect::Scope.find_or_create_by(name: "read")]
|
||||
end
|
||||
end
|
||||
|
||||
factory :auth_with_read_and_ppid, class: Api::OpenidConnect::Authorization do
|
||||
association :o_auth_application, factory: :o_auth_application_with_ppid
|
||||
user
|
||||
|
||||
after(:create) do |auth_with_read|
|
||||
auth_with_read.scopes << [Api::OpenidConnect::Scope.find_or_create_by(name: "openid"),
|
||||
Api::OpenidConnect::Scope.find_or_create_by(name: "read")]
|
||||
end
|
||||
end
|
||||
|
||||
factory :auth_with_read_and_write, class: Api::OpenidConnect::Authorization do
|
||||
o_auth_application
|
||||
user
|
||||
|
||||
after(:create) do |auth_with_read|
|
||||
auth_with_read.scopes << [Api::OpenidConnect::Scope.find_or_create_by(name: "openid"),
|
||||
Api::OpenidConnect::Scope.find_or_create_by(name: "read"),
|
||||
Api::OpenidConnect::Scope.find_or_create_by(name: "write")]
|
||||
end
|
||||
end
|
||||
|
||||
# Factories for the DiasporaFederation-gem
|
||||
|
||||
factory(:federation_person_from_webfinger, class: DiasporaFederation::Entities::Person) do
|
||||
|
|
|
|||
|
|
@ -1,33 +1,21 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Api::OpenidConnect::UserInfoController do
|
||||
# TODO: Replace with factory
|
||||
let!(:client) do
|
||||
Api::OpenidConnect::OAuthApplication.create!(
|
||||
client_name: "Diaspora Test Client",
|
||||
redirect_uris: ["http://localhost:3000/"],
|
||||
ppid: true, sector_identifier_uri: "https://example.com/uri")
|
||||
end
|
||||
let(:auth_with_read) do
|
||||
auth = Api::OpenidConnect::Authorization.create!(o_auth_application: client, user: alice)
|
||||
auth.scopes << [Api::OpenidConnect::Scope.find_or_create_by(name: "openid"),
|
||||
Api::OpenidConnect::Scope.find_or_create_by(name: "read")]
|
||||
auth
|
||||
end
|
||||
let!(:access_token_with_read) { auth_with_read.create_access_token.to_s }
|
||||
let!(:auth_with_read_and_ppid) { FactoryGirl.create(:auth_with_read_and_ppid) }
|
||||
let!(:access_token_with_read) { auth_with_read_and_ppid.create_access_token.to_s }
|
||||
|
||||
describe "#show" do
|
||||
before do
|
||||
@user = auth_with_read_and_ppid.user
|
||||
get api_openid_connect_user_info_path, access_token: access_token_with_read
|
||||
end
|
||||
|
||||
it "shows the info" do
|
||||
json_body = JSON.parse(response.body)
|
||||
expected_sub =
|
||||
alice.pairwise_pseudonymous_identifiers.find_or_create_by(sector_identifier: "https://example.com/uri").guid
|
||||
@user.pairwise_pseudonymous_identifiers.find_or_create_by(sector_identifier: "https://example.com/uri").guid
|
||||
expect(json_body["sub"]).to eq(expected_sub)
|
||||
expect(json_body["nickname"]).to eq(alice.name)
|
||||
expect(json_body["profile"]).to eq(File.join(AppConfig.environment.url, "people", alice.guid).to_s)
|
||||
expect(json_body["nickname"]).to eq(@user.name)
|
||||
expect(json_body["profile"]).to eq(File.join(AppConfig.environment.url, "people", @user.guid).to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,17 +1,7 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Api::OpenidConnect::ProtectedResourceEndpoint, type: :request do
|
||||
# TODO: Replace with factory
|
||||
let!(:client) do
|
||||
Api::OpenidConnect::OAuthApplication.create!(
|
||||
client_name: "Diaspora Test Client", redirect_uris: ["http://localhost:3000/"])
|
||||
end
|
||||
let(:auth_with_read) do
|
||||
auth = Api::OpenidConnect::Authorization.create!(o_auth_application: client, user: alice)
|
||||
auth.scopes << [Api::OpenidConnect::Scope.find_by!(name: "openid"),
|
||||
Api::OpenidConnect::Scope.find_by!(name: "read")]
|
||||
auth
|
||||
end
|
||||
let(:auth_with_read) { FactoryGirl.create(:auth_with_read) }
|
||||
let!(:access_token_with_read) { auth_with_read.create_access_token.to_s }
|
||||
let(:invalid_token) { SecureRandom.hex(32).to_s }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
require "spec_helper"
|
||||
describe Api::OpenidConnect::TokenEndpoint, type: :request do
|
||||
let!(:client) do
|
||||
Api::OpenidConnect::OAuthApplication.create!(
|
||||
redirect_uris: ["http://localhost:3000/"], client_name: "diaspora client",
|
||||
ppid: true, sector_identifier_uri: "https://example.com/uri")
|
||||
end
|
||||
let!(:client) { FactoryGirl.create(:o_auth_application_with_ppid) }
|
||||
let!(:auth) do
|
||||
auth = Api::OpenidConnect::Authorization.find_or_create_by(
|
||||
o_auth_application: client, user: bob, redirect_uri: "http://localhost:3000/")
|
||||
|
|
|
|||
Loading…
Reference in a new issue