Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for empty password before calling PlatformUser #78

Merged
merged 2 commits into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion jarpatcher/src/main/java/jarpatcher/JarPatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void applyPatch(String targetPath, String patchPath, String ignoredPath)
FileOutputStream fos = new FileOutputStream(targetPath.toString());
ZipOutputStream zipOut = new ZipOutputStream(fos);
Set<String> deletedOrPatchedNames = new HashSet<>();
int keeping = 0;

ZipFile zipPatch = new ZipFile(patchPath);
Enumeration<? extends ZipEntry> entries = zipPatch.entries();
Expand Down Expand Up @@ -252,13 +253,15 @@ public void applyPatch(String targetPath, String patchPath, String ignoredPath)
String filename = entry.getName();

if (!deletedOrPatchedNames.contains(filename)) {
logger.info("Keeping: " + filename);
keeping++;
deletedOrPatchedNames.add(filename);
writeEntry(zipOut, deletedOrPatchedNames, zipIn, entry, filename);
}
}
zipIn.close();

logger.info(String.format("Keeping %d ZIP entries", keeping));

zipOut.close();
fos.close();
Files.delete(Paths.get(originalTargetPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,8 @@ public enum PlatformErrno2 {

private static Map<Integer, PlatformErrno2> BY_ERRNO = new HashMap<>();

public static int ERRNO2_BASE = 0x090c0000;

static {
for (PlatformErrno2 e : values()) {
BY_ERRNO.put(e.errno2, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public SafPlatformUser(PlatformClassFactory platformClassFactory) {

@Override
public PlatformReturned authenticate(String userid, String password) {
if ((password == null) || password.isEmpty()) {
return PlatformReturned.builder().success(false).rc(0).errno(PlatformPwdErrno.EINVAL.errno).errno2(PlatformErrno2.ERRNO2_BASE | PlatformErrno2.JRPasswordLenError.errno2).build();
}
try {
Object safReturned = platformClassFactory.getPlatformUserClass()
.getMethod("authenticate", String.class, String.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
package org.zowe.commons.zos.security.platform;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.zowe.commons.zos.security.platform.MockPlatformUser.VALID_PASSWORD;
Expand All @@ -28,9 +29,18 @@ public void returnsNullForValidAuthentication() {
}

@Test
public void returnsDetailsForInvalidAuthentication() {
public void returnsErrorDetailsForInvalidAuthentication() {
PlatformReturned returned = safPlatformUser.authenticate(INVALID_USERID, INVALID_PASSWORD);
assertFalse(returned.isSuccess());
}

@Test
public void returnsErrorDetailsForEmptyPassword() {
PlatformReturned returned = safPlatformUser.authenticate(VALID_USERID, "");
assertFalse(returned.isSuccess());
assertEquals(PlatformPwdErrno.EINVAL.errno, returned.errno);
assertEquals(0, returned.rc);
assertEquals(0x090C02A7, returned.errno2);
assertEquals(PlatformErrno2.JRPasswordLenError, PlatformErrno2.valueOfErrno(returned.errno2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public void failsWithInvalidAuthentication() throws Exception {
when().get("/api/v1/securityTest/authenticatedUser").then().statusCode(401);
}

@Test
public void failsWithEmptyPassword() throws Exception {
RestAssured.authentication = basic(VALID_USERID, "");
when().get("/api/v1/securityTest/authenticatedUser").then().statusCode(401);
}

@Test
public void failsWithExpiredAuthentication() throws Exception {
assumeTrue("The service under test is not running on localhost",
Expand Down