Skip to content

Resiliency to newly-added capabilities #32

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

logiclrd
Copy link
Contributor

@logiclrd logiclrd commented Oct 8, 2024

Backblaze periodically adds new "capabilities" to the B2 API. The current strategy for parsing the models associated with successful logins requires all capabilities to be recognized. This breaks the library every time it happens. This PR aims to provide resiliency to this situation, by making the raw parsing of the "Allowed" structure in new type AllowedRaw just use a list of strings for the capabilities, and then later sorting them into known and unknown capabilities for the actual Allowed object returned by the Connect call.

…ebuggerDisplay to represent unknown capabilities in the returned string.

Made a copy of the Allowed class called AllowedRaw.cs in Bytewizer.Backblaze.Client.Internal that represents capabilities as a list of plain strings, with method ParseCapabilities to transform instances into the original Allowed class. Updated LangVersion in Backblaze.Client.csproj to 8.0 to allow the use of the coalescing assignment operator.
Made a copy of AuthorizedAccountResponse.cs in Bytewizer.Backblaze.Client.Internal that uses AllowedRaw instead of Allowed.
Updated AuthorizeAccountAsync to use AuthorizeAccountResponseRaw for the actual request and then convert the result to the regular AuthorizedAccountResponse structure, with ParseCapabilities splitting off unknown capabilities.
@microcompiler
Copy link
Owner

@logiclrd Thanks again for your contribution. I will take a look that these pull requests this weekend. You don't by any chance have any test cases for these additions?

@logiclrd
Copy link
Contributor Author

logiclrd commented Oct 10, 2024

I tested them by hand, by temporarily undoing the previous PR that added the new capabilities for bucket notifications. I'll have to look into whether there's a simple way to test this from the other side...

- Added an AssemblyInfo class to Backblaze.Client.csproj with an InternalsVisibleTo attribute allowing Backblaze.Tests.Unit access to internal members.
- Added references from Backblaze.Tests.Unit.csproj to NSubstitute, Bogus, FluentAssertions and ASP.NET Core (in order to use Kestrel).
- Added class TestServer.cs to Backblaze.Tests.Unit to create an in-process hosted web server for testing purposes.
- Added text fixture class ApiClientFixture.cs to Backblaze.Tests.Unit with tests of the AuthorizeAccountAync method, including specifically Capabilities Resiliency.
Moved the initialization of Allowed.Capabilities and Allowed.UnknownCapabilities out of the loop in AllowedRaw.ParseCapabilities and added explicit initialization for Capabilities.
…o use explicit strings instead of Faker-generated strings for unknown capability names, since there is a tiny change of faker.Random.Words(3) returning the same string twice.
@logiclrd
Copy link
Contributor Author

@microcompiler There you go. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants