@@ -126,25 +126,35 @@ fn test_unauthorized_coverage() {
126126 ) ) ;
127127 }
128128
129- // If you're here because this assertion failed, check that if you've added
130- // any API operations to Nexus, you've also added a corresponding test in
131- // "unauthorized.rs" so that it will automatically be checked for its
132- // behavior for unauthenticated and unauthorized users. DO NOT SKIP THIS.
133- // Even if you're just adding a stub, see [`Nexus::unimplemented_todo()`].
134- // If you _added_ a test that covered an endpoint from the allowlist --
135- // hooray! Just delete the corresponding line from this file. (Why is this
136- // not `expectorate::assert_contents`? Because we only expect this file to
137- // ever shrink, which is easy enough to fix by hand, and we don't want to
138- // make it easy to accidentally add things to the allowlist.)
139- // let expected_uncovered_endpoints =
140- // std::fs::read_to_string("tests/output/uncovered-authz-endpoints.txt")
141- // .expect("failed to load file of allowed uncovered endpoints");
142-
143- // TODO: Update this to remove overwrite capabilities
144- // See https://github.com/oxidecomputer/expectorate/pull/12
145- assert_contents (
146- "tests/output/uncovered-authz-endpoints.txt" ,
147- uncovered_endpoints. as_str ( ) ,
129+ // If you're here because this assertion failed, you've added an API
130+ // operation to Nexus without adding a corresponding test in
131+ // "unauthorized.rs" to check its behavior for unauthenticated and
132+ // unauthorized users. DO NOT SKIP THIS. Even if you're just adding a stub,
133+ // see [`Nexus::unimplemented_todo()`].
134+ //
135+ // To fix this:
136+ // 1. Add a VerifyEndpoint entry in endpoints.rs for your new endpoint
137+ // 2. Run the test_unauthorized test to verify it works
138+ //
139+ // The allowed uncovered endpoints file should only ever SHRINK (when you
140+ // add coverage for an endpoint). It should never grow. If you've added
141+ // coverage for an endpoint, you can remove it from the allowlist file.
142+ //
143+ // NOTE: We intentionally do NOT use expectorate's assert_contents here
144+ // because we don't want EXPECTORATE=overwrite to allow people to
145+ // accidentally add uncovered endpoints to the allowlist.
146+ let expected_uncovered_endpoints =
147+ std:: fs:: read_to_string ( "tests/output/uncovered-authz-endpoints.txt" )
148+ . expect ( "failed to read uncovered-authz-endpoints.txt" ) ;
149+ assert ! (
150+ uncovered_endpoints == expected_uncovered_endpoints,
151+ "Uncovered endpoints list doesn't match expected.\n \n \
152+ If you ADDED a new endpoint, add authz coverage in endpoints.rs.\n \n \
153+ If you ADDED coverage for an existing endpoint, remove it from \
154+ tests/output/uncovered-authz-endpoints.txt.\n \n \
155+ Expected:\n {}\n \n Actual:\n {}",
156+ expected_uncovered_endpoints,
157+ uncovered_endpoints
148158 ) ;
149159}
150160
0 commit comments