File tree Expand file tree Collapse file tree
main/java/cwms/cda/data/dao
test/java/cwms/cda/api/auth Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4343import java .util .concurrent .TimeUnit ;
4444import java .util .stream .Collectors ;
4545
46- import javax .servlet .http .HttpServletResponse ;
4746import javax .sql .DataSource ;
4847import org .jetbrains .annotations .NotNull ;
4948import org .jooq .DSLContext ;
@@ -56,6 +55,7 @@ public class AuthDao extends Dao<DataApiPrincipal> {
5655 public static final String SCHEMA_TOO_OLD = "The CWMS-Data-API requires schema version "
5756 + "23.03.16 or later to handle authorization operations." ;
5857 public static final String DATA_API_PRINCIPAL = "DataApiPrincipal" ;
58+ public static final String AUTH_ERROR_MSG = "Authentication failed. The API Key may be invalid or no longer active." ;
5959 // At this level we just care that the user has permissions in *any* office
6060 private static final String RETRIEVE_GROUPS_OF_USER =
6161 ResourceHelper .getResourceAsString ("/cwms/data/sql/user_groups.sql" , AuthDao .class );
@@ -204,7 +204,7 @@ private String checkKey(String key) throws CwmsAuthException {
204204 if (rs .next ()) {
205205 return rs .getString (1 );
206206 } else {
207- throw new CwmsAuthException ("No user for key" );
207+ throw new CwmsAuthException (AUTH_ERROR_MSG );
208208 }
209209 }
210210 } catch (SQLException ex ) {
Original file line number Diff line number Diff line change 2626import io .restassured .filter .log .LogDetail ;
2727import io .restassured .specification .RequestSpecification ;
2828
29+ import static cwms .cda .data .dao .AuthDao .AUTH_ERROR_MSG ;
2930import static cwms .cda .data .dao .JsonRatingUtilsTest .loadResourceAsString ;
3031import static io .restassured .RestAssured .given ;
3132import static org .hamcrest .Matchers .*;
@@ -269,7 +270,8 @@ public void test_key_usage() throws Exception {
269270 .then ()
270271 .log ().ifValidationFails (LogDetail .ALL ,true )
271272 .assertThat ()
272- .statusCode (is (HttpCode .UNAUTHORIZED .getStatus ()));
273+ .statusCode (is (HttpCode .UNAUTHORIZED .getStatus ()))
274+ .body ("message" , is (AUTH_ERROR_MSG ));
273275 // fail to use no existent key
274276 given ()
275277 .log ().ifValidationFails (LogDetail .ALL ,true )
@@ -284,7 +286,8 @@ public void test_key_usage() throws Exception {
284286 .then ()
285287 .log ().ifValidationFails (LogDetail .ALL ,true )
286288 .assertThat ()
287- .statusCode (is (HttpCode .UNAUTHORIZED .getStatus ()));
289+ .statusCode (is (HttpCode .UNAUTHORIZED .getStatus ()))
290+ .body ("message" , is (AUTH_ERROR_MSG ));
288291 }
289292
290293 @ Order (6 )
You can’t perform that action at this time.
0 commit comments