Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#53368] add authentication for storage interaction #14954

Merged
merged 4 commits into from
Mar 20, 2024

Conversation

Kharonus
Copy link
Member

@Kharonus Kharonus commented Mar 8, 2024

#53368

WAT?

  • Added the authentication class to storage interaction namespace
  • added unit test that shows the usage and test the auth behaviour of all storage providers

@Kharonus Kharonus self-assigned this Mar 8, 2024
# - :connected If a valid user token is available
# - :failed_authorization If a user token is available, which is invalid and not refreshable
# - :error If an unexpected error occurred
def self.authorization_state(storage:, user:)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore this method, I simply didn't want to cut this out into a separate commit. It is needed later, when authorization state is extracted from the connection manager

@Kharonus Kharonus marked this pull request as ready for review March 8, 2024 12:09
@Kharonus Kharonus requested review from mereghost and a team March 8, 2024 12:09
Copy link
Contributor

@mereghost mereghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see you have the usage be somewhat like so:

CreateTemplateFolderCommand.call(auth: Strategy.new(:oauth_client_credentials), storage: ....)

# or on the inside of an object
class RmRfCommand
  def call(strategy: :basic_auth, storage:, location:)
     Authentication[strategy].call do |authed_http_session|
       do_awesome_requests
     end
  end
end

context 'if a timeout happens' do
before do
request = HTTPX::Request.new(:get, request_url)
httpx_double = class_double(HTTPX, get: HTTPX::ErrorResponse.new(request, 'Timeout happens', {}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 You can actually mock a timeout with WebMock

stub_request(:get, 'https://timeout-as-a-service.com/').to_timeout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, that spec was part of the query tests before, hence webmock was no option (interfering with vcr).

I can change that now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I will refactor that test with the first query that is moved to new auth strategies. Right now, I don't see a good sense in this whole test :/

I wanted to cover the behaviour of httpx to return network errors in a different object. But the handling of it happens inside the queries. So, I would suggest to add a network unit test with webmock, that runs on top of an example query, which is considered a placeholder for all other queries, too.

@Kharonus Kharonus force-pushed the implementation/53368-add-authentication-code-and-tests branch from 2afdf60 to 4f96d4a Compare March 20, 2024 12:35
- use only class, not instance in error payload
@Kharonus Kharonus force-pushed the implementation/53368-add-authentication-code-and-tests branch from 4f96d4a to bf8882c Compare March 20, 2024 12:38
@Kharonus Kharonus requested a review from mereghost March 20, 2024 12:43
@Kharonus Kharonus merged commit 8996a6c into dev Mar 20, 2024
9 checks passed
@Kharonus Kharonus deleted the implementation/53368-add-authentication-code-and-tests branch March 20, 2024 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants