diff options
author | Vijay Venkatesh Kumar <vv770d@att.com> | 2023-02-03 18:42:28 -0500 |
---|---|---|
committer | Vijay Venkatesh Kumar <vv770d@att.com> | 2023-02-03 18:52:24 -0500 |
commit | 147999fca04f4c857209ff9594a69ccb2e2754d1 (patch) | |
tree | 7dd61925f756806000e6f1a20f4925fa5c57184f /src/main | |
parent | 952fa4a24a47b648b68f6d86b73e2cc05e044d46 (diff) |
VESCollector test additions
Add additional tests for ConfigProcessor and ApiAuthInterceptor
Change-Id: Ic8a3debe9bb11997b8aef3dc752017d2b2804b14
Signed-off-by: Vijay Venkatesh Kumar <vv770d@att.com>
Issue-ID: DCAEGEN2-3345
Signed-off-by: Vijay Venkatesh Kumar <vv770d@att.com>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/onap/dcae/common/ConfigProcessors.java | 11 | ||||
-rw-r--r-- | src/main/java/org/onap/dcae/restapi/ApiAuthInterceptor.java | 13 |
2 files changed, 14 insertions, 10 deletions
diff --git a/src/main/java/org/onap/dcae/common/ConfigProcessors.java b/src/main/java/org/onap/dcae/common/ConfigProcessors.java index d1c5e5a0..040a3e6e 100644 --- a/src/main/java/org/onap/dcae/common/ConfigProcessors.java +++ b/src/main/java/org/onap/dcae/common/ConfigProcessors.java @@ -2,8 +2,7 @@ * ============LICENSE_START======================================================= * PROJECT * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * Copyright (C) 2017,2023 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,7 +71,7 @@ public class ConfigProcessors { } - private String evaluate(String str) { + String evaluate(String str) { String value = str; if (str.startsWith("$")) { value = (String) getEventObjectVal(str.substring(1)); @@ -134,7 +133,7 @@ public class ConfigProcessors { } - private void renameArrayInArray(JSONObject jsonObject) // map + void renameArrayInArray(JSONObject jsonObject) // map { log.info("renameArrayInArray"); final String field = jsonObject.getString(FIELD); @@ -437,7 +436,7 @@ public class ConfigProcessors { } - private boolean checkFilter(JSONObject jo, String key, String logicKey) { + boolean checkFilter(JSONObject jo, String key, String logicKey) { String filterValue = jo.getString(key); if (filterValue.contains(":")) { String[] splitVal = filterValue.split(":"); @@ -455,7 +454,7 @@ public class ConfigProcessors { } } - if ("contains".equals(splitVal[0])) { + if ("contains".equals(splitVal[0])) { if ("not".equals(logicKey)) { if (getEventObjectVal(key).toString().contains(splitVal[1])) { log.info(filterValue + "==" + key + "==" + getEventObjectVal(key) + COMP_FALSE); diff --git a/src/main/java/org/onap/dcae/restapi/ApiAuthInterceptor.java b/src/main/java/org/onap/dcae/restapi/ApiAuthInterceptor.java index 8c5fb82a..a9f309a3 100644 --- a/src/main/java/org/onap/dcae/restapi/ApiAuthInterceptor.java +++ b/src/main/java/org/onap/dcae/restapi/ApiAuthInterceptor.java @@ -3,6 +3,7 @@ * org.onap.dcaegen2.collectors.ves * ================================================================================ * Copyright (C) 2018 - 2019 Nokia. All rights reserved. + * Copyright (C) 2023 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -115,18 +116,18 @@ public class ApiAuthInterceptor extends HandlerInterceptorAdapter { return false; } - private boolean isBasicAuth() { + boolean isBasicAuth() { return settings.authMethod().equalsIgnoreCase(AuthMethodType.CERT_BASIC_AUTH.value()); } - private boolean isAuthorized(String authorizationHeader) { + boolean isAuthorized(String authorizationHeader) { try { String decodeCredentials = decodeCredentials(authorizationHeader); String providedUser = extractUser(decodeCredentials); String providedPassword = extractPassword(decodeCredentials); Option<String> maybeSavedPassword = settings.validAuthorizationCredentials().get(providedUser); boolean userRegistered = maybeSavedPassword.isDefined(); - return userRegistered && cryptPassword.matches(providedPassword,maybeSavedPassword.get()); + return userRegistered && verifyCryptPassword(providedPassword,maybeSavedPassword); } catch (Exception e) { LOG.warn(String.format("Could not check if user is authorized (header: '%s')), probably malformed header.", authorizationHeader), e); @@ -134,6 +135,10 @@ public class ApiAuthInterceptor extends HandlerInterceptorAdapter { } } + Boolean verifyCryptPassword(String providedPassword, Option<String> maybeSavedPassword) { + return cryptPassword.matches(providedPassword,maybeSavedPassword.get()); + } + private String extractPassword(String decodeCredentials) { return decodeCredentials.split(":")[1].trim(); } @@ -146,4 +151,4 @@ public class ApiAuthInterceptor extends HandlerInterceptorAdapter { String encodedData = authorizationHeader.split(" ")[1]; return new String(Base64.getDecoder().decode(encodedData)); } -}
\ No newline at end of file +} |