Overview
working on #3500042: Auto-save code components I found that XbConfigEntityHttpApiTest, testJavaScriptComponent and testJavaScriptComponent does test the individual GET request. I confirmed the routee `experience_builder.api.config.get` has
xb_config_entity_type_id: '(pattern|js_component|xb_asset_library)'
so these entity type should support GET for an individual entity
Locally I confirm this by throwing an exception in \Drupal\experience_builder\Controller\ApiConfigControllers::get() both testAssetLibrary() and testJavaScriptComponent() passed
Proposed resolution
Add test coverage
User interface changes
Issue fork experience_builder-3505224
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tedbowI think I started
testAssetLibrary()and probably copied the existingtestJavaScriptComponent()as starting point . So it makes sense that sincetestJavaScriptComponent()didn't test thistestAssetLibrary()would also miss itComment #3
tedbowComment #4
wim leersFor
Patternconfig entities, this is actually tested:So it's only #3499931: HTTP API for code component config entities and #3499933: Storage for CSS shared across in-browser code components (and other use cases in the future) that missed this. #2 explains why both missed it.
Comment #5
tedbowWould be a good idea to refactor this test? looking at
testPattern()don't all the entity types need to test the same thingsassertAuthenticationAndAuthorizationMaybe this not the exact list but whatever the list is shouldn't be same for all entities?
Could we maybe make 1 test method like
For
we could use
array $openapi_invalid_data_cases, array $entity_invalid_data_casesfor both casesI think this would force use to have the same coverage for the all entity types.
If that is too many arguments to a test method we could also do something like
Comment #6
tedbowthere are also big problems with our test coverage for non-empty list responses in `XbConfigEntityHttpApiTest`
\Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testAssetLibrarydoesn't have test coverage for a non-empty response from\Drupal\experience_builder\Controller\ApiConfigControllers::listTrying to add test coverage for this in #3500042: Auto-save code components I found it is not possible because the response has an openapi validation error.
We have
But the "array" schema I don't think works because Looking at
\League\OpenAPIValidation\Schema\Keywords\Type::validateit hasSo it doesn't match "array" for associative arrays.
\Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testJavaScriptComponentdoes seem to test a non-empty list response but the openapi spec for/xb/api/config/js_componentdoesn't have GET specified so there is no openapi validation for the response\Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testPatterndoes seem to have test coverage for non-empty list responses but Looking atpaths./xb/api/config/pattern.getin our openapi there isSo because of #3471064: OpenApi validation is not enforced because openapi.yml uses `patternProperties` which is not supported by our dependencies this doesn't actually trigger validation
I have confirmed this by switching the above to
$ref: '#/components/schemas/LayoutSlot'and
testPattern()still passes 😭So I think they are all broken in a different way 😱
Comment #7
tedbowComment #9
tedbowComment #10
wim leers\League\OpenAPIValidation\PSR7\Exception\NoPath?! 😱This is why it's important to have XB developers proactively looking at our use of OpenAPI, and preferably one person keeping a holistic, abstract view on it. It's supposed to save us time, not cost us time. 😬
It's feeling more and more that OpenAPI is less and less worth it?! 😭 Feels like we need to spend some dedicated time to make it actually robust.
I wonder if we can learn from https://api-platform.com/docs/core/openapi/?
Comment #12
traviscarden commentedSo the questions we're asking now are obviously much broader than the original scope of the issue--almost existential in some ways. There's a lot of--though not total--overlap with #3472632: Decide on an approach for writing tests for OpenAPI integration. I'll go ahead and leave my analysis here until we decide to reorganize the work. For findability, so it's not just buried in the body of this comment, I'll refer to OpenAPI.Tools, which looks very useful.
So in short, what I'm hearing is that our API development is still risky and painful due to poor specification, testing, and quality controls, leading to regressions and surprise obstacles. Specifically...
In order to stabilize API development, we need to figure out how to...
openapi.ymlis valid, correct, and complete. That...GETandPOST.200and500.Here are my thoughts on solutions, taking for granted that they will still revolve around
openapi.ymland PHPUnit:thephpleague/openapi-psr7-validatoris (still) the best solution for enforcing the specification.openapi.yml. That would mostly likely prevent certain errors from creeping in, and it would probably have value in its own right, since anybody in the community could access it.openapi.ymland look for corresponding tests, or we can try to enforce test requirements with interfaces and test class design, or we can look into PHP attribute-based solutions to see if they can provide any help.POSTbodies, we could have one test that just iterates over the paths inopenapi.ymlor uses the autoloader to get all of our endpoint controllers and just posts garbage, asserting that it gets an error response for each one.openapi.ymlcode automatically.That's my first round of analysis. If I were asked, I would probably suggest starting with a linter/static analysis tool, since we'd be likely to get so much out of a good one "for free". Then I would look at our validation library and either fix our implementation or replace it. After that, I would do whatever seemed the most fun at the time. 😉
Hopefully that's what you were looking for, @wim leers. Now's the right time to ask, right? When I've already done it. 😬 🙈
Comment #13
wim leersLet's do this after #3508694: Permissions for XB config entity types adds specific access control.
Comment #14
wim leersComment #15
wim leersComment #16
penyaskito#3508694: Permissions for XB config entity types landed, so I think this is unblocked now.
Comment #17
penyaskitoFor #3519878: ContentCreatorVisibleXbConfigEntityAccessControlHandler's `view` access must refuse access to disabled config entities I ended up hitting the openapi schema bug described by Ted @ #6.1. So that's covered there.
Comment #18
mglamanPicking this up.
Comment #19
mglamanReviewing this, I see
::testJavaScriptComponent: https://git.drupalcode.org/project/experience_builder/-/blob/0.x/tests/s...::testAssetLibrary: https://git.drupalcode.org/project/experience_builder/-/blob/0.x/tests/s...Just to make sure I understand, the limitation is that these test
GETfor the collection endpoint, thenPOST,PATCHon the individual entities and also its auto-saves.So when testing the first list we can do a
GETto verify access? Since the OpenAPI schema has been addressed in another issue.Comment #22
mglamanMarking NR to get feedback on MR questions.
Comment #24
wim leers#19++
Comment #25
wim leersComment #27
wim leers