From d7efeec199686e22277537497c381bba34b89f61 Mon Sep 17 00:00:00 2001 From: Sebastian Rollen Date: Wed, 6 Sep 2023 22:05:14 -0400 Subject: [PATCH] add failing spec --- .../lists_hook_deliveries_for_an_app.json | 90 ++++++++ spec/octokit/client/apps_spec.rb | 208 +++++++++--------- 2 files changed, 198 insertions(+), 100 deletions(-) create mode 100644 spec/cassettes/Octokit_Client_Apps/with_app_installation/_list_app_hook_deliveries/lists_hook_deliveries_for_an_app.json diff --git a/spec/cassettes/Octokit_Client_Apps/with_app_installation/_list_app_hook_deliveries/lists_hook_deliveries_for_an_app.json b/spec/cassettes/Octokit_Client_Apps/with_app_installation/_list_app_hook_deliveries/lists_hook_deliveries_for_an_app.json new file mode 100644 index 000000000..2fd67e655 --- /dev/null +++ b/spec/cassettes/Octokit_Client_Apps/with_app_installation/_list_app_hook_deliveries/lists_hook_deliveries_for_an_app.json @@ -0,0 +1,90 @@ +{ + "http_interactions": [ + { + "request": { + "method": "get", + "uri": "https://api.github.com/app/hook/deliveries", + "body": { + "encoding": "US-ASCII", + "base64_string": "" + }, + "headers": { + "Accept": [ + "application/vnd.github.v3+json" + ], + "User-Agent": [ + "Octokit Ruby Gem 7.1.0" + ], + "Content-Type": [ + "application/json" + ], + "Authorization": [ + "Bearer " + ], + "Accept-Encoding": [ + "gzip;q=1.0,deflate;q=0.6,identity;q=0.3" + ] + } + }, + "response": { + "status": { + "code": 401, + "message": "Unauthorized" + }, + "headers": { + "Server": [ + "GitHub.com" + ], + "Date": [ + "Thu, 07 Sep 2023 01:55:07 GMT" + ], + "Content-Type": [ + "application/json; charset=utf-8" + ], + "Content-Length": [ + "102" + ], + "X-Github-Media-Type": [ + "github.v3; format=json" + ], + "Access-Control-Expose-Headers": [ + "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset" + ], + "Access-Control-Allow-Origin": [ + "*" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubdomains; preload" + ], + "X-Frame-Options": [ + "deny" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Xss-Protection": [ + "0" + ], + "Referrer-Policy": [ + "origin-when-cross-origin, strict-origin-when-cross-origin" + ], + "Content-Security-Policy": [ + "default-src 'none'" + ], + "Vary": [ + "Accept-Encoding, Accept, X-Requested-With" + ], + "X-Github-Request-Id": [ + "D9CB:2887:937315:12B99FA:64F92D7B" + ] + }, + "body": { + "encoding": "UTF-8", + "base64_string": "eyJtZXNzYWdlIjoiQSBKU09OIHdlYiB0b2tlbiBjb3VsZCBub3QgYmUgZGVj\nb2RlZCIsImRvY3VtZW50YXRpb25fdXJsIjoiaHR0cHM6Ly9kb2NzLmdpdGh1\nYi5jb20vcmVzdCJ9\n" + } + }, + "recorded_at": "Thu, 07 Sep 2023 01:55:07 GMT" + } + ], + "recorded_with": "VCR 6.2.0" +} \ No newline at end of file diff --git a/spec/octokit/client/apps_spec.rb b/spec/octokit/client/apps_spec.rb index fd1b97428..eb4128ca6 100644 --- a/spec/octokit/client/apps_spec.rb +++ b/spec/octokit/client/apps_spec.rb @@ -3,85 +3,85 @@ describe Octokit::Client::Apps do before(:each) do Octokit.reset! - @client = oauth_client + @client = oauth_client @jwt_client = Octokit::Client.new(bearer_token: new_jwt_token) - use_vcr_placeholder_for(@jwt_client.bearer_token, '') + use_vcr_placeholder_for(@jwt_client.bearer_token, "") end after(:each) do Octokit.reset! end - describe '.app', :vcr do - it 'returns current App' do + describe ".app", :vcr do + it "returns current App" do response = @jwt_client.app expect(response.id).not_to be_nil - assert_requested :get, github_url('/app') + assert_requested :get, github_url("/app") end - it 'works for GitHub Enterprise installs' do + it "works for GitHub Enterprise installs" do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: 'https://ghe.local/api/v3' + api_endpoint: "https://ghe.local/api/v3" - request = stub_get('https://ghe.local/api/v3/app') + request = stub_get("https://ghe.local/api/v3/app") client.app assert_requested request end end - describe '.find_integration_installations', :vcr do - it 'returns installations for an integration' do + describe ".find_integration_installations", :vcr do + it "returns installations for an integration" do allow(@jwt_client).to receive(:octokit_warn) installations = @jwt_client.find_integration_installations expect(installations).to be_kind_of Array - assert_requested :get, github_url('/app/installations') + assert_requested :get, github_url("/app/installations") expect(@jwt_client).to have_received(:octokit_warn).with(/Deprecated/) end end # .find_integration_installations - describe '.find_app_installations', :vcr do - it 'returns installations for an app' do + describe ".find_app_installations", :vcr do + it "returns installations for an app" do installations = @jwt_client.find_app_installations expect(installations).to be_kind_of Array - assert_requested :get, github_url('/app/installations') + assert_requested :get, github_url("/app/installations") end - it 'works for GitHub Enterprise installs' do + it "works for GitHub Enterprise installs" do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: 'https://ghe.local/api/v3' + api_endpoint: "https://ghe.local/api/v3" - request = stub_get('https://ghe.local/api/v3/app/installations') + request = stub_get("https://ghe.local/api/v3/app/installations") client.find_app_installations assert_requested request end end # .find_app_installations - describe '.find_user_installations', :vcr do - it 'returns installations for a user' do + describe ".find_user_installations", :vcr do + it "returns installations for a user" do response = @client.find_user_installations expect(response.total_count).not_to be_nil expect(response.installations).to be_kind_of(Array) - assert_requested :get, github_url('/user/installations') + assert_requested :get, github_url("/user/installations") end - it 'works for GitHub Enterprise installs' do + it "works for GitHub Enterprise installs" do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: 'https://ghe.local/api/v3' + api_endpoint: "https://ghe.local/api/v3" - request = stub_get('https://ghe.local/api/v3/user/installations') + request = stub_get("https://ghe.local/api/v3/user/installations") client.find_user_installations assert_requested request end - it 'allows auto_pagination', :vcr do + it "allows auto_pagination", :vcr do @client.auto_paginate = true response = @client.find_user_installations(per_page: 1) @@ -91,70 +91,70 @@ end end # .find_user_installations - describe '.find_organization_installation', :vcr do + describe ".find_organization_installation", :vcr do let(:organization) { test_github_org } - it 'returns installation for an organization' do + it "returns installation for an organization" do response = @jwt_client.find_organization_installation(organization) expect(response.id).not_to be_nil - expect(response.target_type).to eq('Organization') + expect(response.target_type).to eq("Organization") assert_requested :get, github_url("/orgs/#{organization}/installation") end - it 'works for GitHub Enterprise installs' do + it "works for GitHub Enterprise installs" do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: 'https://ghe.local/api/v3' + api_endpoint: "https://ghe.local/api/v3" - request = stub_get('https://ghe.local/api/v3/organizations/1234/installation') + request = stub_get("https://ghe.local/api/v3/organizations/1234/installation") client.find_organization_installation(1234) assert_requested request end - it 'allows auto_pagination' do + it "allows auto_pagination" do @jwt_client.auto_paginate = true response = @jwt_client.find_organization_installation(organization, per_page: 1) expect(response.id).not_to be_nil - expect(response.target_type).to eq('Organization') + expect(response.target_type).to eq("Organization") end end # .find_organization_installation - describe '.find_repository_installation', :vcr do - it 'returns installation for an repository' do + describe ".find_repository_installation", :vcr do + it "returns installation for an repository" do response = @jwt_client.find_repository_installation(@test_org_repo) expect(response.id).not_to be_nil - expect(response.target_type).to eq('Organization') + expect(response.target_type).to eq("Organization") assert_requested :get, github_url("/repos/#{@test_org_repo}/installation") end - it 'works for GitHub Enterprise installs' do + it "works for GitHub Enterprise installs" do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: 'https://ghe.local/api/v3' + api_endpoint: "https://ghe.local/api/v3" - request = stub_get('https://ghe.local/api/v3/repos/testing/1234/installation') - client.find_repository_installation('testing/1234') + request = stub_get("https://ghe.local/api/v3/repos/testing/1234/installation") + client.find_repository_installation("testing/1234") assert_requested request end - it 'allows auto_pagination' do + it "allows auto_pagination" do @jwt_client.auto_paginate = true response = @jwt_client.find_repository_installation(@test_org_repo, per_page: 1) expect(response.id).not_to be_nil - expect(response.target_type).to eq('Organization') + expect(response.target_type).to eq("Organization") end end # .find_repository_installation - describe '.find_user_installation', :vcr do + describe ".find_user_installation", :vcr do let(:user) { test_github_login } - it 'returns installation for a user' do + it "returns installation for a user" do response = @jwt_client.find_user_installation(user) expect(response.id).not_to be_nil @@ -162,18 +162,18 @@ assert_requested :get, github_url("/users/#{user}/installation") end - it 'works for GitHub Enterprise installs' do + it "works for GitHub Enterprise installs" do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: 'https://ghe.local/api/v3' + api_endpoint: "https://ghe.local/api/v3" - request = stub_get('https://ghe.local/api/v3/users/1234/installation') - client.find_user_installation('1234') + request = stub_get("https://ghe.local/api/v3/users/1234/installation") + client.find_user_installation("1234") assert_requested request end - it 'allows auto_pagination' do + it "allows auto_pagination" do @jwt_client.auto_paginate = true response = @jwt_client.find_user_installation(user, per_page: 1) @@ -182,48 +182,48 @@ end end # .find_user_installation - context 'with app installation', :vcr do + context "with app installation", :vcr do let(:installation) { test_github_integration_installation } - describe '.installation' do - it 'returns the installation' do + describe ".installation" do + it "returns the installation" do response = @jwt_client.installation(installation) expect(response).to be_kind_of Sawyer::Resource assert_requested :get, github_url("/app/installations/#{installation}") end - it 'works for GitHub Enterprise installs' do + it "works for GitHub Enterprise installs" do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: 'https://ghe.local/api/v3' + api_endpoint: "https://ghe.local/api/v3" - request = stub_get('https://ghe.local/api/v3/app/installations/1234') + request = stub_get("https://ghe.local/api/v3/app/installations/1234") client.installation(1234) assert_requested request end end # .installation - describe '.find_installation_repositories_for_user' do - it 'returns repositories for a user' do + describe ".find_installation_repositories_for_user" do + it "returns repositories for a user" do response = @client.find_installation_repositories_for_user(installation) expect(response.total_count).not_to be_nil expect(response.repositories).to be_kind_of(Array) assert_requested :get, github_url("/user/installations/#{installation}/repositories") end - it 'works for GitHub Enterprise installs' do + it "works for GitHub Enterprise installs" do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: 'https://ghe.local/api/v3' + api_endpoint: "https://ghe.local/api/v3" - request = stub_get('https://ghe.local/api/v3/user/installations/1234/repositories') + request = stub_get("https://ghe.local/api/v3/user/installations/1234/repositories") client.find_installation_repositories_for_user(1234) assert_requested request end - it 'allows auto_pagination', :vcr do + it "allows auto_pagination", :vcr do @client.auto_paginate = true response = @client.find_installation_repositories_for_user(installation, per_page: 1) @@ -233,8 +233,8 @@ end end # .find_installation_repositories_for_user - describe '.create_integration_installation_access_token' do - it 'creates an access token for the installation' do + describe ".create_integration_installation_access_token" do + it "creates an access token for the installation" do allow(@jwt_client).to receive(:octokit_warn) response = @jwt_client.create_integration_installation_access_token(installation) @@ -247,8 +247,8 @@ end end # .create_integration_installation_access_token - describe '.create_app_installation_access_token' do - it 'creates an access token for the installation' do + describe ".create_app_installation_access_token" do + it "creates an access token for the installation" do response = @jwt_client.create_app_installation_access_token(installation) expect(response).to be_kind_of(Sawyer::Resource) @@ -258,12 +258,12 @@ assert_requested :post, github_url("/app/installations/#{installation}/access_tokens") end - it 'works for GitHub Enterprise installs' do + it "works for GitHub Enterprise installs" do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: 'https://ghe.local/api/v3' + api_endpoint: "https://ghe.local/api/v3" - path = 'app/installations/1234/access_tokens' + path = "app/installations/1234/access_tokens" request = stub_post("https://ghe.local/api/v3/#{path}") client.create_app_installation_access_token(1234) @@ -271,28 +271,36 @@ end end # .create_app_installation_access_token - describe '.delete_installation' do - it 'deletes an installation' do + describe ".delete_installation" do + it "deletes an installation" do response = @jwt_client.delete_installation(installation) expect(response).to be_truthy end end # .delete_installation - context 'with app installation access token' do + describe ".list_app_hook_deliveries" do + it "lists hook deliveries for an app" do + response = @jwt_client.list_app_hook_deliveries + expect(response.total_count).not_to be_nil + expect(response.repositories).to be_kind_of(Array) + end + end + + context "with app installation access token" do let(:installation_client) do token = @jwt_client.create_app_installation_access_token(installation).token - use_vcr_placeholder_for(token, '') + use_vcr_placeholder_for(token, "") Octokit::Client.new(access_token: token) end let(:ghe_installation_client) do Octokit::Client.new \ - access_token: 'v1.1f699f1069f60xxx', - api_endpoint: 'https://ghe.local/api/v3' + access_token: "v1.1f699f1069f60xxx", + api_endpoint: "https://ghe.local/api/v3" end - describe '.list_integration_installation_repositories' do - it 'lists the installations repositories' do + describe ".list_integration_installation_repositories" do + it "lists the installations repositories" do allow(installation_client).to receive(:octokit_warn) response = installation_client.list_integration_installation_repositories expect(response.total_count).not_to be_nil @@ -301,21 +309,21 @@ end end # .list_integration_installation_repositories - describe '.list_app_installation_repositories' do - it 'lists the installations repositories' do + describe ".list_app_installation_repositories" do + it "lists the installations repositories" do response = installation_client.list_app_installation_repositories expect(response.total_count).not_to be_nil expect(response.repositories).to be_kind_of(Array) end - it 'works for GitHub Enterprise installs' do - request = stub_get('https://ghe.local/api/v3/installation/repositories') + it "works for GitHub Enterprise installs" do + request = stub_get("https://ghe.local/api/v3/installation/repositories") ghe_installation_client.list_app_installation_repositories assert_requested request end - it 'allows auto_pagination', :vcr do + it "allows auto_pagination", :vcr do installation_client.auto_paginate = true - response = installation_client.list_app_installation_repositories({ per_page: 1 }) + response = installation_client.list_app_installation_repositories({per_page: 1}) expect(response.total_count).to eq 2 expect(response.repositories.count).to eq 2 @@ -324,7 +332,7 @@ end # .list_app_installation_repositories end # with app installation access token - context 'with repository' do + context "with repository" do let(:repository) { test_org_repo } before(:each) do @@ -338,8 +346,8 @@ @client.delete_repository(@repo.full_name) end - describe '.add_repository_to_integration_installation' do - it 'adds the repository to the installation' do + describe ".add_repository_to_integration_installation" do + it "adds the repository to the installation" do allow(@client).to receive(:octokit_warn) response = @client.add_repository_to_integration_installation(installation, @repo.id) expect(response).to be_truthy @@ -347,20 +355,20 @@ end end # .add_repository_to_integration_installation - describe '.add_repository_to_app_installation' do - it 'adds the repository to the installation' do + describe ".add_repository_to_app_installation" do + it "adds the repository to the installation" do response = @client.add_repository_to_app_installation(installation, @repo.id) expect(response).to be_truthy end end # .add_repository_to_app_installation - context 'with installed repository on installation' do + context "with installed repository on installation" do before(:each) do @client.add_repository_to_app_installation(installation, @repo.id) end - describe '.remove_repository_from_integration_installation' do - it 'removes the repository from the installation' do + describe ".remove_repository_from_integration_installation" do + it "removes the repository from the installation" do allow(@client).to receive(:octokit_warn) response = @client.remove_repository_from_integration_installation(installation, @repo.id) expect(response).to be_truthy @@ -368,8 +376,8 @@ end end # .remove_repository_from_integration_installation - describe '.remove_repository_from_app_installation' do - it 'removes the repository from the installation' do + describe ".remove_repository_from_app_installation" do + it "removes the repository from the installation" do response = @client.remove_repository_from_app_installation(installation, @repo.id) expect(response).to be_truthy end @@ -377,24 +385,24 @@ end # with installed repository on installation end # with repository - context 'with repository on GitHub Enterprise' do + context "with repository on GitHub Enterprise" do let(:ghe_client) do Octokit::Client.new \ - access_token: 'x' * 40, - api_endpoint: 'https://ghe.local/api/v3' + access_token: "x" * 40, + api_endpoint: "https://ghe.local/api/v3" end - describe '.add_repository_to_app_installation' do - it 'works for GitHub Enterprise installs' do - request = stub_put('https://ghe.local/api/v3/user/installations/1234/repositories/1234') + describe ".add_repository_to_app_installation" do + it "works for GitHub Enterprise installs" do + request = stub_put("https://ghe.local/api/v3/user/installations/1234/repositories/1234") ghe_client.add_repository_to_app_installation(1234, 1234) assert_requested request end end # .add_repository_to_app_installation - describe '.remove_repository_from_app_installation' do - it 'works for GitHub Enterprise installs' do - request = stub_delete('https://ghe.local/api/v3/user/installations/1234/repositories/1234') + describe ".remove_repository_from_app_installation" do + it "works for GitHub Enterprise installs" do + request = stub_delete("https://ghe.local/api/v3/user/installations/1234/repositories/1234") ghe_client.remove_repository_from_app_installation(1234, 1234) assert_requested request end