summaryrefslogtreecommitdiff
path: root/http
AgeCommit message (Collapse)AuthorFilesLines
2022-08-24Redfish Aggregation: Aggregate CollectionsCarson Labrado1-0/+7
Adds aggregation support for resource collections that take the form of "/redfish/v1/<resource collection>". Collection URIs are identified by the precense of a "Members" array in the response. Resources from satellite BMCs are added to the "Members" array of the response and the "Members@odata.count" value is updated to denote the new array size. These satellite resource URIs that are added also include the prefix associated with that satellite. Note that as a first step this patch assumes a single satellite BMC. There are some potential race conditions that could occur for setups with multiple satellite BMCs. This has been commented in the code and is better left to its own patch. Tested: Queried various collection URIs and the aggregated resources appeared in the response's "Members" array. Querying 'localhost:80/redfish/v1/Chassis?$expand=.($levels=1)' resulted in $expand correctly returning the outputs from querying the URIs of all local and satellite Chassis resources. This would have failed if the satellite Chassis resources were omitted from the "Members" array or the satellite's prefix was not correctly added to the URI. Also queried a collection URI that only existed on the satellite BMC. The AsyncResp was completely overwritten by the response from the satellite BMC. Queries to non-collection URIs resulted in no attempts to add satellite responses to the AsyncResp. Signed-off-by: Carson Labrado <clabrado@google.com> Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I3b379cd57e5a121eb4a344d88fc8e43170ca78a6
2022-08-24Redfish Aggregation: Fixup aggregated URIsCarson Labrado1-0/+30
URIs in the responses returned with Redfish Aggregation enabled will potentially be incorrect since ones from satellite BMCs will not include the associated prefix such as "5B247A_" in the resource ID portion of the URIs. This patch fixes those links so that they include their BMC's associated prefix. Note that a future patch will be needed to add prefixes to aggregated resources that would appear under collection URIs such as "/redfish/v1/Chassis". Tested: Requests were sent to URIs associated with the aggregating BMC and a satellite BMC denoted as "5B247A". The URIs in the responses were successfully updated such that "5B247A_" was added for satellite resources. Signed-off-by: Carson Labrado <clabrado@google.com> Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib4f976fab1ca1e8603f7cf55292732ffb71cd03e
2022-08-24Redfish Aggregation: Router to satellite resourcesCarson Labrado2-0/+11
Adds ability to route requests to either native resources or resources that belong to a satellite BMC as part of Redfish Aggregation. A prefix in the URI denotes if the resource is actually from a satellite BMC. Prefixes are only used to denote satellite resources. The URI of resources on the local/aggregating BMC will remain unchanged. Prefixes are separated from the resource ID by an underscore. This means that underscores cannot be used in the prefix name itself. The prefixes used by satellite BMCs are revealed via D-Bus as well as the config information needed to connect to that BMC. Requests for satellite resources will not be handled locally. Care should be taken to not name any local resources in a way that could cause a collision (e.g. having a Chassis object named "aggregated0_1U" on the aggregating BMC). The patch only covers routing requests. Requests to collection URIs like /redfish/v1/Chassis will only return resources on the local BMC. A future patch will cover adding satellite resources to collections. Also note that URIs returned in the responses will not have the proper prefix included. Fixing these URIs will be addressed in future patches. A number of TODO comments are included in the code to indicate that this functionality (collections and URI fixup) still needs to be implemented. Example URIs w/o Redfish Aggregation: /redfish/v1/Chassis/1U/ /redfish/v1/Systems/system/ /redfish/v1/Managers/bmc/ Example URIs after enabling Redfish Aggregation if the associated resources are located on the local/aggregating BMC: /redfish/v1/Chassis/1U/ /redfish/v1/Systems/system/ /redfish/v1/Managers/bmc/ Example URIs if resources are instead located on a satellite BMC named "aggregated0": /redfish/v1/Chassis/aggregated0_1U/ /redfish/v1/Systems/aggregated0_system/ /redfish/v1/Managers/aggregated0_bmc/ Tested: I was able to query supported resources located on the local BMC as well as on a satellite BMC. Requests with unknown prefixes return a 404. Requests to resource collections only return the resources that are located on the aggregating BMC. Signed-off-by: Carson Labrado <clabrado@google.com> Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I87a3deb730bda95e72ecd3144ea40b0e5ee7d491
2022-08-24Allow parsing urls with extra elementsEd Tanous2-9/+44
Sometimes it is desirable to only parse a portion of a URL, and allow any elements at the end. This comes up significantly in aggregation where parsing "/redfish/v1/<collection>/anything is pretty common. This commit adds a new class, OrMorePaths, that can be used as a placeholder to indicate that more paths should be accepted. Tested: Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: If4fb3991a91560fd3b8b838f912aa36e79ddd2b3
2022-08-17HTTP Client: Further increase httpReadBodyLimitCarson Labrado1-1/+1
A continuation of 4d94272fe54c147974f86788092bbbdd950406aa, increases the size of httpReadBodyLimit to 2^17 bytes (about 128 KB). This is because with Redfish Aggregation we need to be able to handle larger response sizes such as json schema files. The ComputerSystem schema in particular is over 120 KB. Going forward we will not be able to keep increasing the limit. We need a better solution for handling larger response that are larger than httpReadBodyLimit. Tested: Used https://gerrit.openbmc.org/c/openbmc/bmcweb/+/53310/68 to successfully retrieve /redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json from a satellite BMC. Signed-off-by: Carson Labrado <clabrado@google.com> Change-Id: Ida80b8fddbd1df1310d18a77ecfb44b7fdf292ef
2022-08-15Move time utils to be in one placeEd Tanous2-241/+0
We've accumulated several time utility functions in the http classes. Time isn't a core HTTP primitive, so http is not where those functions below. This commit moves all the time functions from the crow::utility namespace into the redfish::time_utils namespace, as well as moves the unit tests. No code changes where made to the individual functions, with the exception of changing the namespace on the unit tests. Tested: Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8493375f60aea31899c84ae703e0f71a17dbdb73
2022-08-10Support micro and milli resolution on timestampsEd Tanous2-3/+40
Supporting higher precision on our timestamps seems worthwhile, and useful to logging implementations for getting more accurate numbers from redfish LogService interfaces. This commit updates the code to add millisecond and microsecond precision to timestamps. Tested: Unit tests pass, pretty good coverage here. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I0914908966702a6cf1bcb59f22761dc24c46b4c3
2022-08-10routing: fix some commentsNan Zhou1-3/+3
Found these when I went through the code path of authx. Tested: comment only changes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Id80725f4bf5f3972e975347dcac8598e2ffab332
2022-08-06Use enum overload for field settingEd Tanous1-1/+2
There are two overloads of addHeader, one that takes a string, and one that takes a boost enum. For most common headers, boost contains a string table with all of those entries anyway, so there's no point in duplicating the strings, and ensures that we don't make trivial mistakes, like capitalization or - versus underscore that aren't caught at compile time. Tested: This saves a trivial amount (572 bytes) of compressed binary size. curl --insecure -vvv --user root:0penBmc https://192.168.7.2/redfish/v1 returns < Content-Type: application/json curl --insecure -vvv -H "Accept: text/html" --user root:0penBmc https://192.168.7.2/redfish/v1 Returns < Content-Type: text/html;charset=UTF-8 Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I34c198b4f9e219247fcfe719f9b3616d35aea3dc
2022-08-05Drop boost::posix_timeEd Tanous3-35/+113
Per the coding standard, if we can support what we need to do with std variants of something, we should prefer that. This commit adds an iso8160 to string method that supports any arbitrary std::chrono::duration object, which allows doing the full range of all of our integer types, and reduces the complexity (and presumably compile times) not pulling in a complex library. Despite the heavy templating, this only appears to add 108 bytes of compressed binary size to bmcweb. This is likely due to the decreased complexity compared to the boost variant (that likely pulls in boost::locale). (Ie 3 template instantiations of the simple one take about the same binary space as 1 complex instantiation). Tested: Unit tests pass (pretty good coverage here) Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I78200fb391b601eba8d2bfd2de0dd868e4390d6b
2022-08-04Preserve headers from the root object on expandEd Tanous1-3/+34
There is a bug where, when running an expand query, headers from the response object get dropped. These headers include OData.type, and the newly minted Link header, as well as possible others. This was actually noted in a TODO, although the author of the TODO, didn't fully understand the consequences at the time, and thought there was no functional impact. To resolve this, this commit resolves the TODO, and allows the Response object to be moved out, instead of having to create a new one, which preserves all the response state. To do this, it creates a move constructor on the Response object for this use. The move constructor is relatively benign, with one caveat, that we might be moving while in a completion handler (as is the most common use). So both the existing operator= and Response() move constructor are amended to handle this case, and simply null out the response object in the copied object, which would be correct behavior, given that each callback handler should only be called once per Response object. Tested: curl --insecure --user root:0penBmc -vvvv https://192.168.7.2/redfish/v1\?\$expand\=\*\(\$levels\=2\) returns the same body as previously, now with the included: OData-Version: 4.0 Allow: Get headers in the response. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I221364dd4304903b37cacb1386f621b073a0a891
2022-08-03Remove jsonMode methodEd Tanous2-7/+2
The jsonMode method is a single line, that basically only sets the content type, and is only called from one place. In all other cases we set the content-type directly from a header, so we should do the same here. Tested: curl --insecure -vvv --user root:0penBmc https://192.168.7.2/redfish/v1 returns < Content-Type: application/json Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I82f6fcf1b574192620ac7b29f97cdd01334c18c4
2022-08-02app: fix -Wpessimizing-moveNan Zhou1-4/+3
clang14 doesn't compile because of "moving a temporary object prevents copy elision". This also alligns the plaintext socket with style of SSL socket. Tested: trivial change. It builds. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I9203cf162d738290306f9ba73ec0ab8f2ca5033c
2022-08-01ServiceRoot Support Link headerEd Tanous1-6/+0
The Redfish standard in section 8.2 states: A Link header containing rel=describedby shall be returned on GET and HEAD requests for Redfish resources. If the referenced JSON Schema is a versioned schema, it shall match the version contained in the value of the @odata.type property returned in this resource. This commit attempts to add this capability to ServiceRoot. Future similar patches will start adding this across the tree. To do this, a few things happen. First, this removes the implicit HEAD handling in the router. Because we now need explicit HEAD handling per-route with specific headers, there's no good way to make this generic. Next, it rearranges the code such that handleServiceRootGet can first call handleServiceRootHead, to avoid duplicating the addHeader call. Tested: Redfish protocol validator passes the RESP_HEADERS_REL_LINK_DESCRIBED_BY check for ServiceRoot. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I92248089a3545432c14f551309ea62332e554647
2022-07-23test treewide: iwyuNan Zhou2-3/+14
These changes are done by running iwyu manually under clang14. Suppressed some obvious impl or details headers. Kept the recommended public headers. IWYU can increase readability, make maintenance easier, and avoid errors in some cases. See details in https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md. This commit also uses its best effort to correct obvious errors through iwyu pragma. See reference here: https://github.com/include-what-you-use/include-what-you-use#how-to-correct-iwyu-mistakes Tested: unit test passed. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I983b6f75601707cbb0f2f04546c3362ff4ba7fee
2022-07-16Remove usages of boost::starts/ends_withEd Tanous2-2/+0
Per the coding standard, now that C++ supports std::string::starts_with and std::string::ends_with, we should be using them over the boost alternatives. This commit goes through and updates all usages. Arguably some of these are incorrect, and instances of common error 13, but because this is mostly a mechanical it intentionally doesn't try to handle it. Tested: Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ic4c6e5d0da90f7442693199dc691a47d2240fa4f
2022-07-15HTTP Client: Fix handling on connection timeoutCarson Labrado1-11/+12
If a destination is not reachable, then the connection will timeout in doConnect(). This causes issues later when the client attempts to resend the message. The error check in doClose() should not exit early since that will result in the connection's status not being marked as closed and thus it will never get reused. Similarly, doCloseAndRetry() should not exit early since that will cause the retry flow to hang and the connection's callback function will not get deleted. Tested: Used Redfish Aggregation patches in the chain through https://gerrit.openbmc.org/c/openbmc/bmcweb/+/54896 to verify that requests to collections such as /redfish/v1/Chassis no longer hang when the specified Satellite BMC does not exist Signed-off-by: Carson Labrado <clabrado@google.com> Change-Id: Ic8369b0de8efb00ff168bc1ed43f1d7fd6c7366a
2022-07-14Simplify logic in router matcherEd Tanous1-4/+6
cppcheck takes a little issue with this logic having some redundancies in it. Regardless of that, it's kind of hard to read; Rearrange the logic so it's easier to read and add comments. Tested: Redfish service validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I0251ceb511e1bc62260b68c430b272d02b90fcb7
2022-07-12Fix const correctness issuesEd Tanous1-2/+2
cppcheck correctly notes that a lot of variables in the new code can be const. Make most of them const. Tested: WIP Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8f37b6353fd707923f533e1d61c5b5419282bf23
2022-07-12Fix const correctness on http Response objectEd Tanous1-4/+4
A number of methods in http::Response were not marked const when they should've been. This is generally not an issue, as most usages of Response are in a non-const context, but as we start using const Response objects more, we need to be more careful about const correctness. Tested: Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8b31e71b6594d9328f106e1367084db42b783b6c
2022-07-08Remove magic numbersEd Tanous1-29/+54
There's lots of magic numbers in this file that we inherited from crow. This commit Adds a TypeCode enum class that can be used in place of the magic numbers. It keeps the same values as were present previously (0-6) in case there are places where this abstraction leaked out, but I believe this catches all of them. Tested: Redfish service validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I063955adb8bf75d9bb6298e29e6e44c210ee9cc3
2022-07-06Remove redfish message from http clientEd Tanous1-1/+1
HttpClient these days is intended to be a generic feature. It should not be relying directly on Redfish messages. In this case, we only ever rely on the return code internally, so replace messages with a simple bad_gateway. Tested: Code compiles. Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ie4bd65dc0b90b75f61ab0e31ca535eefbf0f4ebb
2022-07-05Make resHandler constEd Tanous1-2/+2
cppcheck correctly notes this parameter can be const. Unfortunately we've making a copy here, but looking at the ownership, that can't be avoided simply without a shared_ptr, and that's far more invasive. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib70c89a7a1bc7210219052ba2a44bc7a1c20c7f2
2022-07-02Remove unused variableEd Tanous1-1/+0
This variable was clearly for the print statement below, but then got abandoned at some point. Clean it up. cppcheck found this as well. Tested: Unused code Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I2d143f00dc6956c87ba77d5cbe1b96be631ca795
2022-07-02Fix unused branches in http_clientEd Tanous1-10/+6
cppcheck correctly finds that these branches will always be hit, so the branch is unneeded. Let's start by getting the code cleaned up. Tested: CI only, cpp check. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I7b89337a81e676915243d5bc9d26c24a89c74aef
2022-07-01Fix #includes on http_client.hppEd Tanous1-0/+10
Include what you use. Tested: Code compiles Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I23c89fee6f3e39d2f2a7dc1c3ba2db8819e8adc7
2022-06-30Require explicit decorator on one arg constructorsEd Tanous2-6/+7
We essentially follow this rule already, not relying on implicit operators, although there are a number of cases where in theory we could've implicitly constructed an object. This commit enables the clang-tidy check. Tested: Code compiles, passes clang-tidy. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ia428463313b075c69614fdb326e8c5c094e7adde
2022-06-28Fix shadowed variable issuesEd Tanous4-32/+34
This patchset is the conclusion of a multi-year effort to try to fix shadowed variable names. Variables seem to be shadowed all over, and in most places they exist, there's a "code smell" of things that aren't doing what the author intended. This commit attempts to clean up these in several ways by: 1. Renaming variables where appropriate. 2. Preferring to refer to member variables directly when operating within a class 3. Rearranging code so that pass through variables are handled in the calling scope, rather than passing them through. These patterns are applied throughout the codebase, to the point where -Wshadow can be enabled in meson.build. Tested: Code compiles, unit tests pass. Still need to run redfish service validator. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: If703398c2282f9e096ca2694fd94515de36a098b
2022-06-28http: router_test: fix namespaceNan Zhou1-10/+15
Add using directives and namespaces. Teseted: unit test passed. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I4c04f07484a2c1ce29ae26b523d62071ea03996c
2022-06-28http: router_test: fix headersNan Zhou1-2/+10
IWYU. Use <> for dependency headers and "" for bmcweb headers. Reference: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf12-prefer-the-quoted-form-of-include-for-files-relative-to-the-including-file-and-the-angle-bracket-form-everywhere-else Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I02537f16974ab96a1e4e4e1ee6e1db1a9c679c68
2022-06-28http: utility_test: fix namespaceNan Zhou1-25/+15
Removed unnecessary using directives. Add necessary using directives. Tested: unit test passed. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I36948b531c4e75dbae6837601894839b23b2d3d1
2022-06-28http: utility_test: fix headersNan Zhou1-2/+13
IWYU. Use <> for dependency headers and "" for bmcweb headers. Reference: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf12-prefer-the-quoted-form-of-include-for-files-relative-to-the-including-file-and-the-angle-bracket-form-everywhere-else Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I0338d475990eaf2f0f8105b01d63c2d9bd9fc446
2022-06-28HttpClient: Increase httpReadBodyLimitCarson Labrado1-2/+3
Testing of https://gerrit.openbmc.org/c/openbmc/bmcweb/+/53310 revealed that recvMessage() was failing because the body limit was being exceeded. httpReadBodyLimit was being used to set both the body limit as well as the buffer size. Add a different variable to set the buffer size so that the body limit can be doubled to 16K while the fixed buffer can be set as a smaller size of 4K. Tested: Queries using the mentioned patch stopped failing after applying this change. Signed-off-by: Carson Labrado <clabrado@google.com> Change-Id: I33b62dfc12ff078fba9fb92b2f95a05f41acce3d
2022-06-15bmcweb: Set Retry Policy Valid Response CodesCarson Labrado1-15/+28
Allows individual retry policies to specify what HTTP response codes are considered valid. Sets functions for the EventService and Redfish Aggregation retry policies. Those functions expect a response code and return an error code based on what the response code is. This change is needed because EventService only considers 2XX codes to be valid. Any code outside of that range would trigger a retry attempt. Redfish Aggregation by design will need to return errors outside of that range such as 404. It should not retry to send a message when it receives a 404 from a satellite BMC. Right now 404 is the only error code that is handled differently between the services. Going forward, Redfish Aggregation will likely want to allow other error codes as its functionality is expanded. Tested: Used Redfish-Event-Listener with ssh port forwarding to create 3 subscriptions. I then closed the ssh connection and sent a test event. Bmcweb made 3 retry attempts for each subscription. At that point the max retry amount (as defined by EventService) was reached and bmcweb stop attempting to resend the messages. There were no errors when the Redfish-Event-Listener was correctly connected. Test events resulted in messages being sent for each subscription. Signed-off-by: Carson Labrado <clabrado@google.com> Change-Id: Ifdfaf638d28982ed18998f3ca05280a288e0020a
2022-06-14http/app: iwyuNan Zhou1-0/+7
While working on tests, I found that |app.hpp| is missing some boost headers. I added them manually in this commit. Tested: code compiles. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I1d2fb0f312e1810d836c986e320263a9581f13f2
2022-06-14http_server: remove unused variableNan Zhou1-3/+0
|useSsl| was not referenced anywhere else, so delete it. Tested: code compiles. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ie6ba9c122ab0897254ed3cb0e278d43e8b6a283c
2022-06-06Fix www-authenticate behaviorEd Tanous1-1/+1
bmcweb is in a weird position where, on the one hand, we would like to support Redfish to the specification, while also supporting a secure webui. For better or worse, the webui can't currently use non-cookie auth because of the impacts to things outside of Redfish like websockets. This has lead to some odd code in bmcweb that tries to "detect" whether the browser is present, so we don't accidentally pop up the basic auth window if a user happens to get logged out on an xhr request. Basic auth in a browser actually causes CSRF vulnerabilities, as the browser caches the credentials, so we don't want to make that auth method available at all. Previously, this detection was based on the presence of the user-agent header, but in the years since this code was originally written, a majority of implementations have moved to sending a user-agent by default, which makes this check pretty much useless for its purpose. To work around that, this patchset relies on the X-Requested-With header, to determine if a json payload request was done by xhr. In theory, all browsers will set this header when doing xhr requests, so this should provide a "more correct" solution to this issue. Background: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields "X-Requested-With Mainly used to identify Ajax requests (most JavaScript frameworks send this field with value of XMLHttpRequest)" Tested: curl -vvvv --insecure https://192.168.7.2/redfish/v1/SessionService/Sessions Now returns a WWW-Authenticate header Redfish-protocol-validator now passes 7 more tests from the RESP_HEADERS_WWW_AUTHENTICATE category. Launched webui-vue and logged in. Responses in network tab appear to work, and data populates the page as expected. Used curl to delete redfish session from store with DELETE /redfish/v1/SessionService/Sessions/<SessionId> Then clicked an element on the webui, page forwarded to login page as expected. Opened https://localhost:8000/redfish/v1/CertificateService in a browser, and observed that page forwarded to the login page as it should. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I60345caa41e520c23fe57792bf2e8c16ef144a7a
2022-06-02Make code compile on clang againEd Tanous1-1/+1
The usual updates to make code compile on clang again. Extra semicolons that have snuck in, missing inline and static definitions. Tested: Code compiles on clang. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Id7f889de98cafaa89471d75ed3e3bb97ab3855cd
2022-06-02Allow boost url and url_view to be added to jsonEd Tanous2-0/+34
The latest version of nlohmann seems to have support for adding any arbitrary iterable object as an array in json. Unfortunately, because boost::urls::url produces at iterable of unsigned char, this means that trying to encode urls leads to something like: "@odata.id": [ 47, 114, 101, 100, 102 ] Which is super unhelpful in that it does this implicitly. Given this behavior, there are two options here, make it so that code doesn't compile, or rely on the adl_serializer to just do the expected thing. This patchset opts for the later, to simply to the reasonable behavior, and call string() on the url before loading it into the json. Tested: Unit tests passing. Fixes bug in subsequent patchset. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Id2f49bc8bd7153a0ad0c0fa8be2e13ce7c538e7f
2022-06-01Try to fix the lambda formatting issueEd Tanous5-386/+372
clang-tidy has a setting, LambdaBodyIndentation, which it says: "For callback-heavy code, it may improve readability to have the signature indented two levels and to use OuterScope." bmcweb is very callback heavy code. Try to enable it and see if that improves things. There are many cases where the length of a lambda call will change, and reindent the entire lambda function. This is really bad for code reviews, as it's difficult to see the lines changed. This commit should resolve it. This does have the downside of reindenting a lot of functions, which is unfortunate, but probably worth it in the long run. All changes except for the .clang-format file were made by the robot. Tested: Code compiles, whitespace changes only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib4aa2f1391fada981febd25b67dcdb9143827f43
2022-05-31meson option: make the insecure-disable-auth macro more accurateNan Zhou1-4/+4
The "auth" term is overloaded in meson option and macros. This commit changes the macro from BMCWEB_INSECURE_DISABLE_AUTHENTICATION to BMCWEB_INSECURE_DISABLE_AUTHX, given that if "insecure-disable-auth" is enabled, both authentication and authorization are disabled. Tested: 1. set 'insecure-disable-auth=enabled', no authz nor authn is performed, no crash on AccountService as well. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Iddca1f866d16346bcc2017338fa6f077cb89cef9
2022-05-27Include-what-you-use in http connectionEd Tanous1-0/+4
Lots of #includes were missing in this file that we tangentially got through boost/beast/websocket.hpp. Tested: Code builds. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iac5198f2f65eabaecf47d0fb6bb05bfa5a261f32
2022-05-26auth: change authorization.hpp to authentication.hppNan Zhou1-4/+4
The existing authorization header is actually doing "authentication" work. The authorization is happening in routing.hpp where we fetch the role of the authenticated user and get their privilege set. This commits changes the name of the file, as well as the namespace, to be more precise on what the file actually does. Tested: 1. Trivial change, it builds Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ib91ed70507a7308522c7e5363ed2f4dc279a19d9
2022-05-23bmcweb: Remove hardcoded HTTP verbs and headersCarson Labrado1-42/+40
Modifies HttpClient so that the HTTP verb and headers can be set for each individual message sent. Right now those fields are set when a connection is first created and then reused by each message sent using that connection. Tested: Launched two Event Listener servers that created 6 and 2 subscriptions. Sending a test event resulted in the servers receiving 6 requests and 2 requests, respectively. Change-Id: I8d7e2d54385bc2c403498293820adb584bff8b57 Signed-off-by: Carson Labrado <clabrado@google.com> Signed-off-by: Ed Tanous <edtanous@google.com>
2022-05-17Add callback for response handling to HttpClientCarson Labrado2-12/+56
Adds sendDataWithCallback() which allows the caller to include a callback specifying how to handle the response to that request. This will be utilized for Redfish Aggregation including returning the responses received when forwarding requests to satellite BMCs. Change-Id: I93826c8b254a5f28a982295d4145453352a90fae Signed-off-by: Carson Labrado <clabrado@google.com>
2022-05-17Handle HEAD and Allow headers per the specEd Tanous2-11/+79
The Redfish specification calls out that the Allow header should be returned for all resources to give a client an indication of what actions are allowed on that resource. The router internally has all this data, so this patchset allows the router to construct an allow header value, as well as return early on a HEAD request. This was reverted once here: https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/53637 Due to a redfish validator failure. With the previous patches workaround, this error has now been resolved. Tested: Called curl with various parameters and observed the Allow header curl -vvvv --insecure -X <VERB> --user root:0penBmc https://<bmc>/url HEAD /redfish/v1/SessionService/Sessions returned Allow: GET, POST HEAD /redfish/v1 returned Allow: GET HEAD /redfish/v1/SessionService returned Allow: GET, PATCH POST /redfish/v1 returned Allow: GET (method not allowed) GET /redfish/v1 returned Allow: GET GET /redfish/v1/SessionService returned Allow: GET, PATCH Redfish-Protocol-Validator now reports more tests passing. Prior to this patch: Pass: 255, Warning: 0, Fail: 27, Not tested: 45 After this patch: Pass: 262, Warning: 0, Fail: 21, Not tested: 43 Diff: 7 more tests passing All tests under RESP_HEADERS_ALLOW_METHOD_NOT_ALLOWED and RESP_HEADERS_ALLOW_GET_OR_HEAD are now passing Included unit tests passing. Redfish service validator is now passing. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ibd52a7c2babe19020a0e27fa1ac79a9d33463f25
2022-05-11Refactor HttpClient ClassCarson Labrado1-159/+431
Refactors HttpClient with the following changes: - Convert class to singleton - Replace circular buffers with devectors - Sending queued requests and closing connections handled within their own callback - Add connection pooling (max size 4) - HttpClient supports multiple connections to multiple clients - Retry policies can be set for specific use cases Also modifies its use in the Subscription class to be compatible with the refactored code. It is assumed that a BMC will be able to handle 4 parallel connections and thus the max pool size is set as 4. The max number of queued messages was left unchanged at 50. Eventually we may want to allow tuning of these limits to boost performance. That would come in a future patch. Tested: Launched two Event Listener servers that created 6 and 2 subscriptions. Sending a test event created a connection pool for each server. 4 and 2 connections were added to each pool, respectively and were used to send the test request. For the first pool the 2 extra requests were placed into a queue until connections became available. After a request completed, its associated connection was used to send the next request in the queue. Resending the test event caused those prior connections to be reused instead of new connections being added to the pools. Signed-off-by: Carson Labrado <clabrado@google.com> Change-Id: Iba72b3e342cdc05d1fb972e2e9856763a0a1b3c5
2022-05-11Revert "Handle HEAD and Allow headers per the spec"Ed Tanous2-79/+11
This reverts commit 867b2056d44300db9769e0d0b8883435a179834c. Apparently we have broken the Redfish spec in a way that adding this feature now allows the service validator to find. @odata.id /redfish/v1/UpdateService ERROR - Allow header should NOT contain POST for UpdateService.v1_5_0.UpdateService Need to figure out what to do, but for now, revert to get the build passing again. Change-Id: Ieef20573b9caa03aba6fd2bbc999e517e4b7de3d Signed-off-by: Ed Tanous <edtanous@google.com>
2022-05-10Handle HEAD and Allow headers per the specEd Tanous2-11/+79
The Redfish specification calls out that the Allow header should be returned for all resources to give a client an indication of what actions are allowed on that resource. The router internally has all this data, so this patchset allows the router to construct an allow header value, as well as return early on a HEAD request. Tested: Called curl with various parameters and observed the Allow header curl -vvvv --insecure -X <VERB> --user root:0penBmc https://<bmc>/url HEAD /redfish/v1/SessionService/Sessions returned Allow: GET, POST HEAD /redfish/v1 returned Allow: GET HEAD /redfish/v1/SessionService returned Allow: GET, PATCH POST /redfish/v1 returned Allow: GET (method not allowed) GET /redfish/v1 returned Allow: GET GET /redfish/v1/SessionService returned Allow: GET, PATCH Redfish-Protocol-Validator now reports more tests passing. Prior to this patch: Pass: 255, Warning: 0, Fail: 27, Not tested: 45 After this patch: Pass: 262, Warning: 0, Fail: 21, Not tested: 43 Diff: 7 more tests passing All tests under RESP_HEADERS_ALLOW_METHOD_NOT_ALLOWED and RESP_HEADERS_ALLOW_GET_OR_HEAD are now passing Included unit tests passing. Change-Id: Ib99835050b15eb4f419bfd21375b26e4db74fa2c Signed-off-by: Ed Tanous <edtanous@google.com>
2022-05-05Implement etag headersEd Tanous1-0/+12
This commit implements a limited support for the production of etags on json resources. It is intended to cause two things: 1. To get bmcweb to pass the PROTO_ETAG_ON_GET_ACCOUNT check, as well as the redfish spec, which states: "Implementations shall support the return of ETag headers for GET requests of ManagerAccount resources." 2. Begin discussions on what client-facing caching could look like in the future, and to implement the fewest lines of code this author could think of, with the hope of extending it later. As written, it injects into the Response class a method that, for json responses, uses std::hash<json> to generate an etag. This was chosen under the assumption that it caused the least binary impact, and is already a function provided by nlohmann, so required minimal implementation effort to get something that functioned to the standard: https://json.nlohmann.me/api/basic_json/std_hash/#version-history I'm open to discussions if this should be improved in the future to include more entropy, or to be a "weak" etag, but I think starting with std::hash is a good first step. This patchset intentionally does notimplement handling of the If-None-Match, or If-Match headers that a caching client would likely send that implements this. That is not explicitly required by the spec, relatively complex, and probably has consequences that this author doesn't want to write the test cases for (yet). This lack of support makes this patchset largely only "useful" in passing the tests, and implementing the spec to the letter, it does not generalize a caching client feature that improves performance. Tested: curl -vvvv --insecure --user root:0penBmc https://192.168.7.2/redfish/v1 Contains in the response: ETag: "765E4548" The redfish protocol validator now passes the PROTO_ETAG_ON_GET_ACCOUNT test, which increases our passing test count by 4 compared to previously. Current counts are 352 passing, 30 failing, 36 not tested. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I3389b2ba98bf1276e1cb2d9c5954437b924f2d94