OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#66464] Add a spec.
Pavel Balashoud3eb6cbaf7af
diff --git a/modules/storages/spec/common/storages/adapters/authentication_strategies/oauth_user_token_spec.rb b/modules/storages/spec/common/storages/adapters/authentication_strategies/oauth_user_token_spec.rbindex e174dbd4721..92d1b542a0c 100644--- a/modules/storages/spec/common/storages/adapters/authentication_strategies/oauth_user_token_spec.rb+++ b/modules/storages/spec/common/storages/adapters/authentication_strategies/oauth_user_token_spec.rb@@ -108,8 +108,70 @@ module Storagesendend- context "with invalid oauth access token", vcr: "auth/nextcloud/user_token_access_token_invalid" do- it_behaves_like "successful response", refreshed: true+ context "with invalid oauth access token" do+ it "must refresh token and return success" do+ storage+ token = OAuthClientToken.last+ user_request_stub_1 = stub_request(:get, "https://nextcloud.local/ocs/v1.php/cloud/user")+ .with(+ headers: {+ "Accept" => "*/*",+ "Accept-Encoding" => "gzip, deflate",+ "Authorization" => "Bearer #{token.access_token}",+ "User-Agent" => "httpx.rb/1.3.4"+ }+ )+ .to_return(status: 401, body: <<~XML, headers: {})+ <?xml version="1.0"?>+ <ocs>+ <meta>+ <status>failure</status>+ <statuscode>997</statuscode>+ <message>Current user is not logged in</message>+ <totalitems></totalitems>+ <itemsperpage></itemsperpage>+ </meta>+ <data/>+ </ocs>+ XML+ user_request_stub_2 = stub_request(:get, "https://nextcloud.local/ocs/v1.php/cloud/user")+ .with(+ headers: {+ "Accept" => "*/*",+ "Accept-Encoding" => "gzip, deflate",+ "Authorization" => "Bearer NEW_ACCESS_TOKEN",+ "User-Agent" => "httpx.rb/1.3.4"+ }+ )+ .to_return(status: 200, body: <<~JSON, headers: { "Content-Type" => "application/json; charset=utf-8" })+ {"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK","totalitems":"","itemsperpage":""},"data":{"enabled":true,"storageLocation":"/var/www/html/data/admin","id":"admin","lastLogin":1709888213000,"backend":"Database","subadmin":[],"quota":{"free":962269761536,"used":1137306515,"total":963407068051,"relative":0.12,"quota":-3},"manager":"","avatarScope":"v2-federated","email":null,"emailScope":"v2-federated","additional_mail":[],"additional_mailScope":[],"displayname":"admin","display-name":"admin","displaynameScope":"v2-federated","phone":"","phoneScope":"v2-local","address":"","addressScope":"v2-local","website":"","websiteScope":"v2-local","twitter":"","twitterScope":"v2-local","fediverse":"","fediverseScope":"v2-local","organisation":"","organisationScope":"v2-local","role":"","roleScope":"v2-local","headline":"","headlineScope":"v2-local","biography":"","biographyScope":"v2-local","profile_enabled":"1","profile_enabledScope":"v2-local","groups":["admin"],"language":"en","locale":"","notify_email":null,"backendCapabilities":{"setDisplayName":true,"setPassword":true}}}}+ JSON+ token_request_stub = stub_request(:post, "https://nextcloud.local/index.php/apps/oauth2/api/v1/token")+ .with(+ body: { "client_id" => token.oauth_client.client_id,+ "client_secret" => token.oauth_client.client_secret,+ "grant_type" => "refresh_token",+ "refresh_token" => token.refresh_token,+ "scope" => "" },+ headers: {+ "Accept" => "*/*",+ "Accept-Encoding" => "gzip, deflate",+ "Content-Type" => "application/x-www-form-urlencoded",+ "User-Agent" => "httpx.rb/1.3.4"+ }+ )+ .to_return(status: 200, body: <<~JSON, headers: { "Content-Type" => "application/json; charset=utf-8" })+ {"access_token":"NEW_ACCESS_TOKEN","token_type":"Bearer","expires_in":3600,"refresh_token":"NEW_REFRESH_TOKEN","user_id":"admin"}+ JSON+ result = Authentication[strategy_data].call(storage:) { |http| make_request(http) }++ expect(user_request_stub_1).to have_been_made.once+ expect(user_request_stub_2).to have_been_made.once+ expect(token_request_stub).to have_been_made.once++ expect(result).to be_success+ expect(result.value!).to eq("EXPECTED_RESULT")+ endendcontext "with valid access token", vcr: "auth/one_drive/user_token" dodiff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/auth/nextcloud/user_token_access_token_invalid.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/auth/nextcloud/user_token_access_token_invalid.ymldeleted file mode 100644index 4fdeeb62ec2..00000000000--- a/modules/storages/spec/support/fixtures/vcr_cassettes/auth/nextcloud/user_token_access_token_invalid.yml+++ /dev/null@@ -1,234 +0,0 @@-----http_interactions:-- request:- method: get- uri: https://nextcloud.local/ocs/v1.php/cloud/user- body:- encoding: US-ASCII- string: ''- headers:- Authorization:- - Bearer <BEARER TOKEN>- User-Agent:- - httpx.rb/1.2.3- Accept:- - "*/*"- Accept-Encoding:- - gzip, deflate- response:- status:- code: 401- message: Unauthorized- headers:- Cache-Control:- - no-cache, no-store, must-revalidate- Content-Security-Policy:- - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'- Content-Type:- - application/xml; charset=utf-8- Date:- - Fri, 08 Mar 2024 09:27:40 GMT- Expires:- - Thu, 19 Nov 1981 08:52:00 GMT- Feature-Policy:- - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone- 'none';payment 'none'- Pragma:- - no-cache- Referrer-Policy:- - no-referrer- Server:- - Apache/2.4.57 (Debian)- Set-Cookie:- - ocirabgzify6=c7e0c4a6c6d3bc29a2e1acbe831870d9; path=/; secure; HttpOnly; SameSite=Lax,- oc_sessionPassphrase=aK6rp4uRxDhSdbFlsS2wwbV0GtDKFTm%2BS20i427N16mObEOZ3sJx8JkhZg3Z5y5mald%2BtyNRj61cR38tPXAISfUHlzFDqgcybJZnpYOpS3ryIE6AgbGKhWfC9uwFlmy0;- path=/; secure; HttpOnly; SameSite=Lax, ocirabgzify6=c7e0c4a6c6d3bc29a2e1acbe831870d9;- path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;- path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,- __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,- 31-Dec-2100 23:59:59 GMT; SameSite=strict, ocirabgzify6=c7e0c4a6c6d3bc29a2e1acbe831870d9;- path=/; secure; HttpOnly; SameSite=Lax- X-Content-Type-Options:- - nosniff- X-Frame-Options:- - SAMEORIGIN- X-Permitted-Cross-Domain-Policies:- - none- X-Powered-By:- - PHP/8.2.16- X-Request-Id:- - gA5FAKPA4oYwmVQaEXPq- X-Robots-Tag:- - noindex, nofollow- X-Xss-Protection:- - 1; mode=block- Content-Length:- - '230'- body:- encoding: UTF-8- string: |- <?xml version="1.0"?>- <ocs>- <meta>- <status>failure</status>- <statuscode>997</statuscode>- <message>Current user is not logged in</message>- <totalitems></totalitems>- <itemsperpage></itemsperpage>- </meta>- <data/>- </ocs>- recorded_at: Fri, 08 Mar 2024 09:27:40 GMT-- request:- method: post- uri: https://nextcloud.local/index.php/apps/oauth2/api/v1/token- body:- encoding: ASCII-8BIT- string: grant_type=refresh_token&scope=&client_id=7fj7lpG0GOqwOGhHAyfGwd1oEgtbTto7mctu0IaSN3SE79o9Xs0q8k3kDiEwXDrM&client_secret=j7RoyauWeIpMc7cYdY3lewCGKxdgiAowonpGzmAuj9iRSvYBAGXhP7hvz9Hp7skR&refresh_token=HRrpqZowJjD6OzBnwkpFTJAnAGQFUkhJ7En4ZpPtkhrPEIuRohVY56ooknlsrRVdIUOUPvyqtTzXomxDcOXvjnXhpREA18CkYOYQ3s2fxqOlk9u9mNrSTxHaqD0mpItw- headers:- User-Agent:- - httpx.rb/1.2.3- Accept:- - "*/*"- Accept-Encoding:- - gzip, deflate- Content-Type:- - application/x-www-form-urlencoded- Content-Length:- - '328'- response:- status:- code: 200- message: OK- headers:- Cache-Control:- - no-cache, no-store, must-revalidate- Content-Encoding:- - gzip- Content-Security-Policy:- - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'- Content-Type:- - application/json; charset=utf-8- Date:- - Fri, 08 Mar 2024 09:27:40 GMT- Expires:- - Thu, 19 Nov 1981 08:52:00 GMT- Feature-Policy:- - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone- 'none';payment 'none'- Pragma:- - no-cache- Referrer-Policy:- - no-referrer- Server:- - Apache/2.4.57 (Debian)- Set-Cookie:- - ocirabgzify6=3aacffae684309baee15b9c37fdc5d6f; path=/; secure; HttpOnly; SameSite=Lax,- oc_sessionPassphrase=NWWi25ZMVtFYunofSBJ%2FURKXYfXSZcL7xY6suwb880gAnfhY0aIxdy4UkUy0ZvP8Ef4YLHIA7hIkpGcTpGwVw8v9j8L9Wbqs45Cx2dIfrcWxhhdLDWuyN74rOsRSE9JR;- path=/; secure; HttpOnly; SameSite=Lax, ocirabgzify6=3aacffae684309baee15b9c37fdc5d6f;- path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;- path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,- __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,- 31-Dec-2100 23:59:59 GMT; SameSite=strict, ocirabgzify6=3aacffae684309baee15b9c37fdc5d6f;- path=/; secure; HttpOnly; SameSite=Lax- X-Content-Type-Options:- - nosniff- X-Frame-Options:- - SAMEORIGIN- X-Nextcloud-Bruteforce-Throttled:- - 200ms- X-Permitted-Cross-Domain-Policies:- - none- X-Powered-By:- - PHP/8.2.16- X-Request-Id:- - NQjl2frIpdjcHCrSVhdL- X-Robots-Tag:- - noindex, nofollow- X-Xss-Protection:- - 1; mode=block- Content-Length:- - '270'- body:- encoding: UTF-8- string: '{"access_token":"<ACCESS_TOKEN>","token_type":"Bearer","expires_in":3600,"refresh_token":"pF4QFI0ncfUUunsKCIauOUXUm8TQXrEEOvpfE2sGXPxYTsNr4FtPg0sxORfYXdxa5B98McVn3vbKblLwtA8QnKq7ATZAxtjDnDBBBXy7nUe5Z3exYeFaHcZdWwcYzv1w","user_id":"admin"}'- recorded_at: Fri, 08 Mar 2024 09:27:41 GMT-- request:- method: get- uri: https://nextcloud.local/ocs/v1.php/cloud/user- body:- encoding: US-ASCII- string: ''- headers:- Ocs-Apirequest:- - 'true'- Accept:- - application/json- User-Agent:- - httpx.rb/1.2.3- Accept-Encoding:- - gzip, deflate- Authorization:- - Bearer <BEARER TOKEN>- response:- status:- code: 200- message: OK- headers:- Cache-Control:- - no-cache, no-store, must-revalidate- Content-Encoding:- - gzip- Content-Security-Policy:- - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'- Content-Type:- - application/json; charset=utf-8- Date:- - Fri, 08 Mar 2024 09:27:41 GMT- Expires:- - Thu, 19 Nov 1981 08:52:00 GMT- Feature-Policy:- - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone- 'none';payment 'none'- Pragma:- - no-cache- Referrer-Policy:- - no-referrer- Server:- - Apache/2.4.57 (Debian)- Set-Cookie:- - ocirabgzify6=e0e76ba543cb281d8c6de45f13379227; path=/; secure; HttpOnly; SameSite=Lax,- oc_sessionPassphrase=LcCCzBcktAmO9u5darmcMbX1GfvpLBkrSIyqOXu%2Bs0sfHD60nfff%2BuXHIaMRh9AhQXAzOvPgXFsekDAjqvbFn%2FswvgJMJyWt3w9bVSzDoQ8c%2BZmsdnzpaIyZXSnfTgAm;- path=/; secure; HttpOnly; SameSite=Lax, ocirabgzify6=e0e76ba543cb281d8c6de45f13379227;- path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;- path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,- __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,- 31-Dec-2100 23:59:59 GMT; SameSite=strict, ocirabgzify6=e0e76ba543cb281d8c6de45f13379227;- path=/; secure; HttpOnly; SameSite=Lax, ocirabgzify6=e0e76ba543cb281d8c6de45f13379227;- path=/; secure; HttpOnly; SameSite=Lax, ocirabgzify6=e0e76ba543cb281d8c6de45f13379227;- path=/; secure; HttpOnly; SameSite=Lax, ocirabgzify6=e0e76ba543cb281d8c6de45f13379227;- path=/; secure; HttpOnly; SameSite=Lax, ocirabgzify6=e0e76ba543cb281d8c6de45f13379227;- path=/; secure; HttpOnly; SameSite=Lax, ocirabgzify6=e0e76ba543cb281d8c6de45f13379227;- path=/; secure; HttpOnly; SameSite=Lax, ocirabgzify6=e0e76ba543cb281d8c6de45f13379227;- path=/; secure; HttpOnly; SameSite=Lax- X-Content-Type-Options:- - nosniff- X-Frame-Options:- - SAMEORIGIN- X-Permitted-Cross-Domain-Policies:- - none- X-Powered-By:- - PHP/8.2.16- X-Request-Id:- - SIriQ7P07385wqbUaP7M- X-Robots-Tag:- - noindex, nofollow- X-Xss-Protection:- - 1; mode=block- Content-Length:- - '496'- body:- encoding: UTF-8- string: '{"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK","totalitems":"","itemsperpage":""},"data":{"enabled":true,"storageLocation":"\/var\/www\/html\/data\/admin","id":"admin","lastLogin":1709888213000,"backend":"Database","subadmin":[],"quota":{"free":962269761536,"used":1137306515,"total":963407068051,"relative":0.12,"quota":-3},"manager":"","avatarScope":"v2-federated","email":null,"emailScope":"v2-federated","additional_mail":[],"additional_mailScope":[],"displayname":"admin","display-name":"admin","displaynameScope":"v2-federated","phone":"","phoneScope":"v2-local","address":"","addressScope":"v2-local","website":"","websiteScope":"v2-local","twitter":"","twitterScope":"v2-local","fediverse":"","fediverseScope":"v2-local","organisation":"","organisationScope":"v2-local","role":"","roleScope":"v2-local","headline":"","headlineScope":"v2-local","biography":"","biographyScope":"v2-local","profile_enabled":"1","profile_enabledScope":"v2-local","groups":["admin"],"language":"en","locale":"","notify_email":null,"backendCapabilities":{"setDisplayName":true,"setPassword":true}}}}'- recorded_at: Fri, 08 Mar 2024 09:27:41 GMT-recorded_with: VCR 6.2.0