summaryrefslogtreecommitdiff
path: root/test/include
AgeCommit message (Collapse)AuthorFilesLines
2025-08-26Fix includesEd Tanous1-2/+0
Our includes haven't been enforced by tidy in a while. Run the script, check in the result, minus the false positives. Change-Id: I6a6da26f5ba5082d9b4aa17cdc9f55ebd8cd41a6 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-06-27Rearrange featuresEd Tanous3-174/+0
The backends are different things compared to generic code. Today, these are all included in the /include folder, but it's not very clear what options control which backends, or how things map together. This also means that we can't separate ownership between the various companies. This commit is a proposal to try to create a features folder, separated by the code for the various backends, to make interacting with this easier. It takes the form features/<option name>/files.hpp features/<option name>/files_test.hpp Note, redfish-core was already at top level, and contains lots of code, so to prevent lots of conflicts, it's simply symlinked into that folder to make clear that it is a backend, but not to move the implementation and cause code conflicts. Tested: Unit tests pass. Code compiles. Change-Id: Idcc80ffcfd99c876734ee41d53f894ca5583fed5 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-06-04Remove implicit conversionsEd Tanous1-4/+16
Since 2020, nlohmann has recognized that implicit conversions to and from json are an issue. Many bugs have been caused at both development time and runtime due to unexpected implicit conversions from json to std::string/int/bool. This commit disables implicit conversions using JSON_USE_IMPLICIT_CONVERSIONS [1]. This option will become the default in the future. That comment was written 3 years ago at this point, so we should prepare. Tested: Redfish service validator passes. [1] https://json.nlohmann.me/api/macros/json_use_implicit_conversions/ Change-Id: Id6cc47b9bbf8889e4777fd6d77ec992f3139962c Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-03-14mtls: implement UPN parse modeMalik Akbar Hashemi Rafsanjani1-0/+45
This commit is intended to implement the UserPrincipalName (UPN) parse mode on mutual TLS (MTLS). By implementing this we can use the X509 certificate extension Subject Alternative Name (SAN), specifically UPN to be used as the username In our case, this feature is needed because we have a specific format on our Subject CN of X509 certificate. This format cannot directly mapped to the username of bmcweb because it contains special characters (`/` and `:`), which cannot exist in the username. Changing the format of our Subject CN is very risky. By enabling this feature we can use other field, which is the SAN extension to be used as the username and do not change our Subject CN on the X509 certificate In general, by implementing this feature, we can enable multiple options for the system. There might be other cases where we want to have the username of the bmcweb is not equal to the Subject CN of the certificate, instead the username is added as the UserPrincipalName field in the certificate The format of the UPN is `<username>@<domain>` [1][2]. The format is similar to email format. The domain name identifies the domain in which the user is located [3] and it should match the device name's domain (domain forest). Tested - Test using `generate_auth_certificate.py` (extended on patch [4]) - Manual testing (please see the script mentioned above for more detail) - Setup certificate with UPN inside SAN extension - Change the CertificateMappingAttribute to use UPN - Get request to `/SessionService/Sessions` - Run unit tests [1] UPN Format: https://learn.microsoft.com/en-us/windows/win32/secauthn/user-name-formats#user-principal-name [2] UPN Properties: https://learn.microsoft.com/en-us/windows/win32/ad/naming-properties#userprincipalname [3] UPN Glossary: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wcce/719b890d-62e6-4322-b9b1-1f34d11535b4#gt_9d606f55-b798-4def-bf96-97b878bb92c6 [4] Patch Testing Script: https://gerrit.openbmc.org/c/openbmc/bmcweb/+/78837 Change-Id: I490da8b95aee9579546971e58ab2c4afd64c5997 Signed-off-by: Malik Akbar Hashemi Rafsanjani <malikrafsan@meta.com>
2025-01-20Use SPDX identifiersEd Tanous13-0/+26
SPDX identifiers are simpler, and reduce the amount of cruft we have in code files. They are recommended by linux foundation, and therefore we should do as they allow. This patchset does not intend to modify any intent on any existing copyrights or licenses, only to standardize their inclusion. [1] https://www.linuxfoundation.org/blog/blog/copyright-notices-in-open-source-software-projects Change-Id: I935c7c0156caa78fc368c929cebd0f068031e830 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-12-28Handle all possible subtypesEd Tanous1-0/+9
Accept header allows any possible parameter value, and expects that unknown property subtypes are simply ignored. We were previously enforcing that things either match q=<number> or have no params. bmcweb has no usage of the params, but allow them to parse silently per the spec in case someone sends them. [1] https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types#structure_of_a_mime_type This more meets the intent. In theory we could parse only q and charset values, but allowing any key/values here makes us more resilient against new mime types being added. Tested: Unit tests included and passing Change-Id: I1500be0da4c0c72185ee5bda5dfc31885dc6102d Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-12-09Add content-encoding parserEd Tanous1-0/+27
Similar to content-type, add an http content-encoding parser. Tested: Unit tests pass. Change-Id: Ic62809934f84804c910458184de19ca9a4207ce5 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-12-03Make accepts a real parserEd Tanous1-0/+33
We somewhat copped out a little with regards to this originally, because writing parsers is hard, and we don't have to implement the full field of what the Accepts header allows. We should aim to be correct where we can, so implement a real parser that parses values, including the floats. Tested: Unit tests pass, good coverage. Change-Id: I1b4232929367d230641be9f41f5af6e6dbcea037 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-09-04Remove IWYU pragmasEd Tanous9-51/+13
These were added as part of d5c80ad9c07b94465d8ea62d2b6f87c30cac765e: test treewide: iwyu Since then, Nan hasn't been very active on the project, and to my knowledge, since the initial run, we've never used IWYU again. clang-include-cleaner seems to work well without needing these pragmas, and is what we're using, even if it's less useful than IWYU. Remove all mention of IWYU. Tested: Code compiles. Change-Id: I06feedeeac9a114f5bdec81d59ca83223efd8aa7 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-09-04Fix includesEd Tanous2-3/+3
This commit is automatically generated by enabling clang-include-fixer. Tested: Code compiles. Change-Id: I475d7b9d43e95bbdeeaadf11905d3b2a60aa8ef3 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-08-17clang-format: re-format for clang-18Patrick Williams3-26/+31
clang-format-18 isn't compatible with the clang-format-17 output, so we need to reformat the code with the latest version. The way clang-18 handles lambda formatting also changed, so we have made changes to the organization default style format to better handle lambda formatting. See I5e08687e696dd240402a2780158664b7113def0e for updated style. See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement. Change-Id: Iceec1dc95b6c908ec6c21fb40093de9dd18bf11a Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2024-07-12Make schemas selectableEd Tanous1-2/+2
Which schemas are installed should be selectable in both a meson config, and trivially by forks. This commit gets us closer to that idea. It does it in several ways, first, the code for generating JsonSchemaFile resources has been changed to be generated at runtime, based on files on disk. This is slightly slower, but allows installing schemas from anywhere, and matches the CSDL handling. Next, the schema folders are separated into two sets csdl -> This includes the complete schema pack from dmtf installed -> this includes only the schemas the bmc includes Similar folders exist for json-schema and json-schema-installed. This allows any additional schemas to be a single symlink addition. Note, this also checks in all of the dmtf json schemas, not just the versions we use. This allows us to update the schema pack without needing to break our versions we ship. Because the static files are now selectable, all files need to be in a folder. This forces the css and image for the redfish built-in gui to be moved. Tested: /redfish/v1/JsonSchemas returns the correct result /redfish/v1/JsonSchemas/UpdateService returns a JsonSchemaFile instance /redfish/v1/JsonSchemas/UpdateService/UpdateService<version>json returns the JsonSchemaFile contents. Redfish service validator passes. Change-Id: Ie96b2e4b623788dc2ec94eb40fcfd80325f0d826 Signed-off-by: Ed Tanous <ed@tanous.net>
2024-06-10Break out random ID methodsEd Tanous1-0/+9
The method of creating a random ID from an openssl random generator of a particular length is something that is generally useful, and something we can write unit tests for. Add it. Tested: Redfish service validator login flows work correctly in redfish service validator. Change-Id: Ic3b58d33f1421f3eb39e2d57585958f87f6fb8ea Signed-off-by: Ed Tanous <ed@tanous.net>
2024-06-10Make cert generate for readonly directoriesEd Tanous1-0/+26
When run from a development PC, we shouldn't REQUIRE that the cert directory exists or is writable. This commit reworks the SSL cert generation to generate a string with the certification info, instead of writing it to disk and reading it back. This allows bmcweb to start up in read-only environments, or environments where there isn't access to the key information. Tested: Launching the application on a dev desktop without an ssl directory present no longer crashes. Change-Id: I0d44eb1ce8d298986c5560803ca2d72958d3707c Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-27Move to process v2Ed Tanous1-9/+9
Boost process v2 brings some significant benefits to our launching of processes[1]. In bmcweb terms: 1. The code is radically simpler, which decreaeses compile times, and reduces the scope for code scanning tools. 2. The code now uses standard asio pipes instead of inventing its own. 3. Separate compilation. Tested: We don't have a lot of unit tests for the virtual media stuff that I can run, but we do have unit tests for credentials pipe, which in this change have been ported over, so the feature works. Unit tests are passing. [1] https://www.boost.org/doc/libs/1_80_0/doc/html/boost_process/v2.html#boost_process.v2.introduction Change-Id: Ia20226819d75ff6e492f8852185f0b73e8f5cf83 Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-18Remove ibm locks featureSunitha Harish1-314/+0
This feature was introduced to manage the operation sync at BMC while multiple clients manage the BMC. This feature scope has gone away and it is not a simple code to maintain as per the growing standards of bmcweb. This commit removes the feature from this repo. Tested by: Locks routes are not available anymore Change-Id: I257225cfb1f43d7d5dadb21a28a2ee5345c5112a Signed-off-by: Sunitha Harish <sunithaharish04@gmail.com> Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-01Delete old testsEd Tanous1-54/+0
These tests are commented out, and have been for a very long time. Clearly they don't matter. Change-Id: I084378ee9bc43bb64bd6e134398bbf2173d263ff Signed-off-by: Ed Tanous <ed@tanous.net>
2024-03-28Add misc-include-cleanerEd Tanous7-6/+16
And fix the includes that are wrong. Note, there is a very large ignore list included in the .clang-tidy configcfile. These are things that clang-tidy doesn't yet handle well, like knowing about a details include. Change-Id: Ie3744f2c8cba68a8700b406449d6c2018a736952 Signed-off-by: Ed Tanous <ed@tanous.net>
2024-02-06Make tests not require body interactionEd Tanous1-197/+221
The muitipart test interacts with some significant details of the response class. This was largely only done because Request lacked an addHeader method that Request already had. Add addHeader() method to the Request class, and adapt multipart unit tests to use it. Tested: Unit tests pass. Unit test only changes. Change-Id: Icb3b92dce6d17011ae0063a962678173b1b01a87 Signed-off-by: Ed Tanous <ed@tanous.net>
2024-01-19Remove some boost includesEd Tanous1-0/+25
The less we rely on boost, and more on std algorithms, the less people have to look up, and the more likely that our code will deduplicate. Replace all uses of boost::algorithms with std alternatives. Tested: Redfish Service Validator passes. Change-Id: I8a26f39b5709adc444b4178e92f5f3c7b988b05b Signed-off-by: Ed Tanous <edtanous@google.com>
2024-01-09Fix spelling mistakesEd Tanous1-11/+11
These were found with: codespell -w $(git ls-files | grep "\.[hc]\(pp\)\?$") At some point in the future, we might want to get this enabled in CI. Change-Id: Iccb57b2adfd06a2e177e99db2923fe4e8e329118 Signed-off-by: Ed Tanous <ed@tanous.net>
2023-09-25Clean up vm CredentialPipeEd Tanous1-0/+41
This code is needlessly complicated for what it does. Even with the intent, which is secure buffer cleanup, it's trivial to encase all this into a single class that accepts the strings by rvalue reference, then cleans them up afterward. Doing this also cleans up a potential lifetime problem, where if the unix socket returned immediately, it would've invalidated the buffers that were being sent. It also moves to async_write, instead of async_write_some. The former could in theory fail if the socket blocks (unlikely in this scenario) but it's good to handle anyway. Tested: Need some help here. There's no backend for this, so we might just have to rely on inspection. Change-Id: I9032d458f8eb7a0689bee575aae611641bacee26 Signed-off-by: Ed Tanous <edtanous@google.com>
2023-07-14AsyncResolve cleanups and error handlingEd Tanous1-0/+25
The Async DBus resolver really has nothing to do with crow, which is our core http library namespace and has some opportunistic cleanups that can be done. This commit moves it into the bmcweb namespace (unimportantly) and breaks out one of the larger functions such that it can be unit tested, and unit tests it. Tested: Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ie3cfbb0ef81a027a1ad42358c04967a517471117
2023-07-12Use openssl random number generatorEd Tanous1-0/+23
We already have a generator class. We should use it. Wrap this into a function that can be unit tested, and add unit tests. Note, some files also needed to change name, because random.hpp conflicts with the built in random, and causes circular build problems. This commit changes it to ossl_random. Tested: Unit tests pass. Now has coverage. Redfish service validator passes. Change-Id: I5f8eee1af5f4843a352c6fd0e26d67fd3320ef53 Signed-off-by: Ed Tanous <edtanous@google.com>
2023-05-25Fix some includesEd Tanous1-1/+2
System includes should be included with <>, in-tree includes should be included with "". This was found manually, with the help of the following grep statement[1]. git grep -o -h "#include .*" | sort | uniq Tested: Code compiles Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I1a6b2a5ba35ccbbb61c67b7c4b036a2d7b3a36a3
2023-05-19Write test capable of catching regressionsEd Tanous1-13/+37
This is a pretty simple test, but should be able to catch the regression injected in the previous commit. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I67de097059a6e0dd8d2c02c1aa6c69954a6d7be3
2023-05-18Add a unit test for dumpHtmlEd Tanous1-0/+41
We have no unit tests for this. This isn't very extensive, but we should have at least one. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I212ee528b354f2ed47f88076be009fd6e16fb760
2023-05-12ibm-locks: shut up clang-tidy by disabling codePatrick Williams1-1/+4
There is code in ibm/locks that has had clang-tidy warnings disabled for a while due to multiple safety and endianness issues. The code has not been fixed in a while and with clang-16 it is unable to be exempted further. Disable it until someone who cares can fix this in the proper way. ``` ../include/ibm/locks.hpp:522:14: error: 'p' is an unsafe pointer used for buffer access [-Werror,-Wunsafe-buffer-usage] uint8_t* p = reinterpret_cast<uint8_t*>(&resourceId1); ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../include/ibm/locks.hpp:527:25: note: used in buffer access here uint8_t pPosition = p[position]; ^ ../include/ibm/locks.hpp:524:14: error: 'q' is an unsafe pointer used for buffer access [-Werror,-Wunsafe-buffer-usage] uint8_t* q = reinterpret_cast<uint8_t*>(&resourceId2); ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../include/ibm/locks.hpp:529:25: note: used in buffer access here uint8_t qPosition = q[position]; ``` Signed-off-by: Patrick Williams <patrick@stwcx.xyz> Change-Id: I8a7fcbed1099419ad1715c86ffcbfef20820251e
2023-05-11clang-format: copy latest and re-formatPatrick Williams3-3/+3
clang-format-16 has some backwards incompatible changes that require additional settings for best compatibility and re-running the formatter. Copy the latest .clang-format from the docs repository and reformat the repository. Change-Id: I75f89d2959b0f1338c20d72ad669fbdc1d720835 Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2023-02-21Disable token compress in strEd Tanous1-2/+23
There are certain cases where we use this split function, and we expect tokens to be read out. For example: /xyz/openbmc_project/sensors/unit/name Should split into a "" in the first position. This use case is not common, and a quick grep shows only two places in the code expect this behavior. Boost::split has this behavior already, which is what this function is emulating. While we could fix these, in the end they should be following the rules outlined in COMMON_ERRORS.md, which disallow this kind of parsing completely. Tested: New unit tests passing. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iec3dcbf2b495b2b3b4ed419172c4133b16f7c65d
2023-02-17Implement alternative to on boost::splitEd Tanous1-0/+31
boost::split has a documented false-positive in clang-tidy. While normally we'd handle this with NOLINTNEXTLINE, this doesn't appear to work in all cases. Unclear why, but seems to be due to some of our lambda callback complexity. Each of these uses is a case where we should be using a more specific check, rather than split, but for the moment, this is the best we have. Tested: clang-tidy passes. [1] https://github.com/llvm/llvm-project/issues/40486 Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I144c6610cb740287b7225e2be03b4142a64f9563
2022-10-12header cleanupsNan Zhou1-1/+1
This commit fixed several places (but not all) where wrong include directory is specified and prevent the clean up in the chidren changes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ibbba62e2c0cfe3583a65f1befa1b233bd3eebf19
2022-10-05Fixed issues with multipart parserKrzysztof Grobelny1-9/+183
- Index was not checked against size before dereference. Which cased to override memory. - Header without colon could put parser into invalid state. Now it will return with error. - Content after boundary was not correctly discarded. - Parser did not check body for final boudary. Now missing final boundary will return with error. Tested: - Tested that payload with header without colon doesn't cause memory corruption anymore. Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com> Change-Id: I12f496ab5f53e6c088cdfdf2e96be636d66f7c7f
2022-09-22Fix content-type return behavior for */*Ed Tanous1-15/+20
An HTTP header of Accepts: */* throws a big wrench into our implementation for a couple reasons. First, because it's the default in a lot of commonly-used libraries, and second, because clients use it when they certainly don't mean what the specification says it should mean "ie, I accept ANY type". This commit tries to address some of that, by making an explicit option for content-type="ANY" and pushes it to the individual callers to handle explicitly as if it were yet another type. In most protocols, there's a "most common" representation, so protocols are free to use that, or to explicitly handle it, and require that the user be explicit. Tested: Redfish Protocol Validator no longer locks up. (TBD, getting bugs filed with protocol validator for this missing Accepts header). For ServiceRoot GET /redfish/v1 Accepts: application/json - returns json GET /redfish/v1 Accepts: */* - returns json GET /redfish/v1 Accepts: text/html - returns html GET /redfish/v1 no-accepts header - returns json Redfish-service-validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iae6711ae587115d3e159a48a6fc46a903ed6c403
2022-09-22treewide: reorganize unit testsNan Zhou8-0/+981
Like other C++ projects, unit tests normally are in a separate repo and respect the folder structure of the file under test. This commit deleted all "ut" folder and move tests to a "test" folder. The test folder also has similar structure as the main folder. This commit also made neccessary include changes to make codes compile. Unused tests are untouched. Tested: unit test passed. Reference: [1] https://github.com/grpc/grpc/tree/master/test [2] https://github.com/boostorg/core/tree/414dfb466878af427d33b36e6ccf84d21c0e081b/test [3] Many other OpenBMC repos: https://github.com/openbmc/entity-manager/tree/master/test [4] https://stackoverflow.com/questions/2360734/whats-a-good-directory-structure-for-larger-c-projects-using-makefile Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I4521c7ef5fa03c47cca5c146d322bbb51365ee96