Skip to content

Commit

Permalink
[cleanup] Perform test cleanup as noted by codeql and sonarlint
Browse files Browse the repository at this point in the history
  • Loading branch information
hazendaz committed Jan 21, 2024
1 parent 5af366e commit a4e1e5e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2010-2020 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
* Copyright (c) 2010-2024 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -95,8 +95,7 @@ void tearDown() {
this.filter.destroy();

if (LMErr.NERR_Success == this.resultOfNetAddUser) {
Assertions.assertEquals(LMErr.NERR_Success,
Netapi32.INSTANCE.NetUserDel(null, this.userInfo.usri1_name.toString()));
Assertions.assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, this.userInfo.usri1_name));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2010-2023 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
* Copyright (c) 2010-2024 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -95,8 +95,7 @@ void tearDown() {
this.filter.destroy();

if (LMErr.NERR_Success == this.resultOfNetAddUser) {
Assertions.assertEquals(LMErr.NERR_Success,
Netapi32.INSTANCE.NetUserDel(null, this.userInfo.usri1_name.toString()));
Assertions.assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, this.userInfo.usri1_name));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2010-2020 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
* Copyright (c) 2010-2024 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -95,8 +95,7 @@ void tearDown() {
this.filter.destroy();

if (LMErr.NERR_Success == this.resultOfNetAddUser) {
Assertions.assertEquals(LMErr.NERR_Success,
Netapi32.INSTANCE.NetUserDel(null, this.userInfo.usri1_name.toString()));
Assertions.assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, this.userInfo.usri1_name));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2010-2020 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
* Copyright (c) 2010-2024 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -89,14 +89,12 @@ void testLogonUser() {
Assumptions.assumeTrue(LMErr.NERR_Success == Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null));
try {
final IWindowsAuthProvider prov = new WindowsAuthProviderImpl();
final IWindowsIdentity identity = prov.logonUser(userInfo.usri1_name.toString(),
userInfo.usri1_password.toString());
Assertions.assertTrue(identity.getFqn().endsWith("\\" + userInfo.usri1_name.toString()));
final IWindowsIdentity identity = prov.logonUser(userInfo.usri1_name, userInfo.usri1_password.toString());
Assertions.assertTrue(identity.getFqn().endsWith("\\" + userInfo.usri1_name));
Assertions.assertFalse(identity.isGuest());
identity.dispose();
} finally {
Assertions.assertEquals(LMErr.NERR_Success,
Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
Assertions.assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name));
}
}

Expand All @@ -113,16 +111,14 @@ void testImpersonateLoggedOnUser() {
Assumptions.assumeTrue(LMErr.NERR_Success == Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null));
try {
final IWindowsAuthProvider prov = new WindowsAuthProviderImpl();
final IWindowsIdentity identity = prov.logonUser(userInfo.usri1_name.toString(),
userInfo.usri1_password.toString());
final IWindowsIdentity identity = prov.logonUser(userInfo.usri1_name, userInfo.usri1_password.toString());
final IWindowsImpersonationContext ctx = identity.impersonate();
Assertions.assertTrue(userInfo.usri1_name.toString().equals(Advapi32Util.getUserName()));
Assertions.assertEquals(userInfo.usri1_name, Advapi32Util.getUserName());
ctx.revertToSelf();
Assertions.assertFalse(userInfo.usri1_name.toString().equals(Advapi32Util.getUserName()));
Assertions.assertNotEquals(userInfo.usri1_name, Advapi32Util.getUserName());
identity.dispose();
} finally {
Assertions.assertEquals(LMErr.NERR_Success,
Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
Assertions.assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2010-2020 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
* Copyright (c) 2010-2024 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -94,8 +94,7 @@ void tearDown() {
this.filter.destroy();

if (LMErr.NERR_Success == this.resultOfNetAddUser) {
Assertions.assertEquals(LMErr.NERR_Success,
Netapi32.INSTANCE.NetUserDel(null, this.userInfo.usri1_name.toString()));
Assertions.assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, this.userInfo.usri1_name));
}
}

Expand All @@ -110,7 +109,7 @@ void tearDown() {
@Test
void testImpersonateEnabled() throws IOException, ServletException {

Assertions.assertFalse(Advapi32Util.getUserName().equals(MockWindowsAccount.TEST_USER_NAME),
Assertions.assertNotEquals(MockWindowsAccount.TEST_USER_NAME, Advapi32Util.getUserName(),
"Current user shouldn't be the test user prior to the test");

final SimpleHttpRequest request = new SimpleHttpRequest();
Expand Down Expand Up @@ -138,7 +137,7 @@ void testImpersonateEnabled() throws IOException, ServletException {

Assertions.assertEquals(MockWindowsAccount.TEST_USER_NAME, filterChain.getUserName(),
"Test user should be impersonated");
Assertions.assertFalse(Advapi32Util.getUserName().equals(MockWindowsAccount.TEST_USER_NAME),
Assertions.assertNotEquals(MockWindowsAccount.TEST_USER_NAME, Advapi32Util.getUserName(),
"Impersonation context should have been reverted");
} finally {
if (windowsPrincipal != null) {
Expand All @@ -158,7 +157,7 @@ void testImpersonateEnabled() throws IOException, ServletException {
@Test
void testImpersonateDisabled() throws IOException, ServletException {

Assertions.assertFalse(Advapi32Util.getUserName().equals(MockWindowsAccount.TEST_USER_NAME),
Assertions.assertNotEquals(MockWindowsAccount.TEST_USER_NAME, Advapi32Util.getUserName(),
"Current user shouldn't be the test user prior to the test");
final SimpleHttpRequest request = new SimpleHttpRequest();
request.setMethod("GET");
Expand All @@ -182,9 +181,9 @@ void testImpersonateDisabled() throws IOException, ServletException {
Assertions.assertTrue(principal instanceof WindowsPrincipal);
windowsPrincipal = (WindowsPrincipal) principal;

Assertions.assertFalse(MockWindowsAccount.TEST_USER_NAME.equals(filterChain.getUserName()),
Assertions.assertNotEquals(MockWindowsAccount.TEST_USER_NAME, filterChain.getUserName(),
"Test user should not be impersonated");
Assertions.assertFalse(Advapi32Util.getUserName().equals(MockWindowsAccount.TEST_USER_NAME),
Assertions.assertNotEquals(MockWindowsAccount.TEST_USER_NAME, Advapi32Util.getUserName(),
"Impersonation context should have been reverted");
} finally {
if (windowsPrincipal != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2010-2020 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
* Copyright (c) 2010-2024 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -89,14 +89,12 @@ void testLogonUser() {
Assumptions.assumeTrue(LMErr.NERR_Success == Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null));
try {
final IWindowsAuthProvider prov = new WindowsAuthProviderImpl();
final IWindowsIdentity identity = prov.logonUser(userInfo.usri1_name.toString(),
userInfo.usri1_password.toString());
Assertions.assertTrue(identity.getFqn().endsWith("\\" + userInfo.usri1_name.toString()));
final IWindowsIdentity identity = prov.logonUser(userInfo.usri1_name, userInfo.usri1_password.toString());
Assertions.assertTrue(identity.getFqn().endsWith("\\" + userInfo.usri1_name));
Assertions.assertFalse(identity.isGuest());
identity.dispose();
} finally {
Assertions.assertEquals(LMErr.NERR_Success,
Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
Assertions.assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name));
}
}

Expand All @@ -113,16 +111,14 @@ void testImpersonateLoggedOnUser() {
Assumptions.assumeTrue(LMErr.NERR_Success == Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null));
try {
final IWindowsAuthProvider prov = new WindowsAuthProviderImpl();
final IWindowsIdentity identity = prov.logonUser(userInfo.usri1_name.toString(),
userInfo.usri1_password.toString());
final IWindowsIdentity identity = prov.logonUser(userInfo.usri1_name, userInfo.usri1_password);
final IWindowsImpersonationContext ctx = identity.impersonate();
Assertions.assertTrue(userInfo.usri1_name.toString().equals(Advapi32Util.getUserName()));
Assertions.assertEquals(userInfo.usri1_name, Advapi32Util.getUserName());
ctx.revertToSelf();
Assertions.assertFalse(userInfo.usri1_name.toString().equals(Advapi32Util.getUserName()));
Assertions.assertNotEquals(userInfo.usri1_name, Advapi32Util.getUserName());
identity.dispose();
} finally {
Assertions.assertEquals(LMErr.NERR_Success,
Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
Assertions.assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name));
}
}

Expand Down Expand Up @@ -254,7 +250,7 @@ void testSecurityContextsExpire() throws InterruptedException {
}
WindowsAuthProviderTest.LOGGER.info("Cached security contexts: {}",
Integer.valueOf(provider.getContinueContextsSize()));
Assertions.assertFalse(max == provider.getContinueContextsSize());
Assertions.assertNotEquals(max, provider.getContinueContextsSize());
} finally {
if (serverContext != null) {
serverContext.dispose();
Expand Down

0 comments on commit a4e1e5e

Please sign in to comment.