Skip to content

Commit c52c55e

Browse files
author
rathnapandi
committed
- Add junit tests for basic auth password comparison
- Fix #483
1 parent b5f51fa commit c52c55e

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerPoliciesAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public Policy getPolicyForName(PolicyType type, String name) throws AppException
122122
List<Policy> policies = this.mappedPolicies.get(type);
123123

124124
for (Policy policy : policies) {
125-
LOG.info("Policy Name : {}", policy.getName());
125+
LOG.debug("Policy Name : {}", policy.getName());
126126
if (policy.getName().equals(name)) {
127127
return policy;
128128
}

modules/apim-adapter/src/test/java/com/axway/apim/api/model/AuthenticationProfileTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,59 @@ public void compareBasicAuthProfiles(){
147147
Assert.assertEquals(authenticationProfileFromGateway, authenticationProfile);
148148
}
149149

150+
@Test
151+
public void compareBasicAuthProfilesWithDifferentPassword(){
152+
AuthenticationProfile authenticationProfile = new AuthenticationProfile();
153+
authenticationProfile.setName("_default");
154+
authenticationProfile.setType(AuthType.http_basic);
155+
authenticationProfile.setIsDefault(true);
156+
Map<String, Object> parameters = new HashMap<>();
157+
parameters.put("username","admin");
158+
parameters.put("password", Utils.getEncryptedPassword());
159+
parameters.put("_id_", 0);
160+
161+
authenticationProfile.setParameters(parameters);
162+
AuthenticationProfile authenticationProfileFromGateway = new AuthenticationProfile();
163+
authenticationProfileFromGateway.setName("_default");
164+
authenticationProfileFromGateway.setIsDefault(true);
165+
authenticationProfileFromGateway.setType(AuthType.http_basic);
166+
167+
parameters = new HashMap<>();
168+
parameters.put("username","admin");
169+
parameters.put("password", Utils.getEncryptedPassword()+1);
170+
parameters.put("_id_", 0);
171+
172+
authenticationProfileFromGateway.setParameters(parameters);
173+
Assert.assertNotEquals(authenticationProfileFromGateway, authenticationProfile);
174+
}
175+
176+
@Test
177+
public void compareBasicAuthProfilesWithSamePassword(){
178+
AuthenticationProfile authenticationProfile = new AuthenticationProfile();
179+
authenticationProfile.setName("_default");
180+
authenticationProfile.setType(AuthType.http_basic);
181+
authenticationProfile.setIsDefault(true);
182+
Map<String, Object> parameters = new HashMap<>();
183+
parameters.put("username","admin");
184+
parameters.put("password", Utils.getEncryptedPassword());
185+
parameters.put("_id_", 0);
186+
187+
authenticationProfile.setParameters(parameters);
188+
AuthenticationProfile authenticationProfileFromGateway = new AuthenticationProfile();
189+
authenticationProfileFromGateway.setName("_default");
190+
authenticationProfileFromGateway.setIsDefault(true);
191+
authenticationProfileFromGateway.setType(AuthType.http_basic);
192+
193+
parameters = new HashMap<>();
194+
parameters.put("username","admin");
195+
parameters.put("password", Utils.getEncryptedPassword());
196+
parameters.put("_id_", 0);
197+
198+
authenticationProfileFromGateway.setParameters(parameters);
199+
Assert.assertEquals(authenticationProfileFromGateway, authenticationProfile);
200+
}
201+
202+
150203
@Test
151204
public void compareApikeyAuthProfiles(){
152205
AuthenticationProfile authenticationProfile = new AuthenticationProfile();

modules/apis/src/main/java/com/axway/apim/apiimport/APIChangeState.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ private void getChanges() throws AppException {
8383
String getterMethodName = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
8484
Method method = desiredAPI.getClass().getMethod(getterMethodName, null);
8585
Method method2 = actualAPI.getClass().getMethod(getterMethodName, null);
86-
Object desiredValue = method.invoke(desiredAPI, null);
87-
Object actualValue = method2.invoke(actualAPI, null);
86+
Object desiredValue = method.invoke(desiredAPI, null);
87+
Object actualValue = method2.invoke(actualAPI, null);
8888
APIPropertyAnnotation property = field.getAnnotation(APIPropertyAnnotation.class);
8989
if (desiredValue == null && actualValue == null) continue;
9090
if (desiredValue == null && property.ignoreNull()) {
@@ -287,7 +287,7 @@ public boolean isAdminAccountNeeded() throws AppException {
287287
boolean orgAdminSelfServiceEnabled = APIManagerAdapter.getInstance().getConfigAdapter().getConfig(APIManagerAdapter.getInstance().hasAdminAccount()).getOadminSelfServiceEnabled();
288288
if (orgAdminSelfServiceEnabled) return false;
289289
return (!getDesiredAPI().getState().equals(API.STATE_UNPUBLISHED) && !getDesiredAPI().getState().equals(API.STATE_DELETED)) ||
290-
(getActualAPI() != null && !getActualAPI().getState().equals(API.STATE_UNPUBLISHED));
290+
(getActualAPI() != null && !getActualAPI().getState().equals(API.STATE_UNPUBLISHED));
291291
}
292292

293293
public String waiting4Approval() throws AppException {

modules/apps/src/main/java/com/axway/apim/appexport/impl/JsonApplicationExporter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ public void writeContent(ExportApplication app, ObjectMapper mapper, File localF
118118
}
119119
}
120120
private String getExportFolder(ExportApplication app) {
121-
String appName = app.getName();
122-
appName = appName.replace(" ", "-");
123-
return appName;
121+
return Utils.replaceSpecialChars(app.getName());
124122
}
125123

126124
public static void writeBytesToFile(byte[] bFile, String fileDest) throws AppException {

modules/organizations/src/main/java/com/axway/apim/organization/impl/JsonOrgExporter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ public void writeContent(ExportOrganization org, ObjectMapper mapper, File local
9999
}
100100

101101
private String getExportFolder(ExportOrganization org) {
102-
String name = org.getName();
103-
name = name.replace(" ", "-");
104-
return name;
102+
return Utils.replaceSpecialChars(org.getName());
105103
}
106104

107105
@Override

0 commit comments

Comments
 (0)