From 5af366e645550640a633618d4da32b4c0582a492 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Sat, 20 Jan 2024 20:23:43 -0500 Subject: [PATCH 1/2] [git] Ignore checkstyle / pmd cache directories --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 62b478d9f8..a2cc81fe59 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ Source/JNA/release.properties .cache/ .profiler/ .github/keys/ +.checkstyle +.pmd +.pmdruleset.xml From a4e1e5ef1f1ac23b982592b16681fe59e866448a Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Sat, 20 Jan 2024 20:24:08 -0500 Subject: [PATCH 2/2] [cleanup] Perform test cleanup as noted by codeql and sonarlint --- .../java/waffle/spring/ImpersonateTest.java | 5 ++--- .../java/waffle/spring/ImpersonateTest.java | 5 ++--- .../java/waffle/servlet/ImpersonateTest.java | 5 ++--- .../windows/auth/WindowsAuthProviderTest.java | 20 +++++++---------- .../java/waffle/servlet/ImpersonateTest.java | 15 ++++++------- .../windows/auth/WindowsAuthProviderTest.java | 22 ++++++++----------- 6 files changed, 30 insertions(+), 42 deletions(-) diff --git a/Source/JNA/waffle-spring-security5/src/test/java/waffle/spring/ImpersonateTest.java b/Source/JNA/waffle-spring-security5/src/test/java/waffle/spring/ImpersonateTest.java index d126c9e4d0..057d35c1f7 100644 --- a/Source/JNA/waffle-spring-security5/src/test/java/waffle/spring/ImpersonateTest.java +++ b/Source/JNA/waffle-spring-security5/src/test/java/waffle/spring/ImpersonateTest.java @@ -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 @@ -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)); } } diff --git a/Source/JNA/waffle-spring-security6/src/test/java/waffle/spring/ImpersonateTest.java b/Source/JNA/waffle-spring-security6/src/test/java/waffle/spring/ImpersonateTest.java index 933b0f981c..1c576229ac 100644 --- a/Source/JNA/waffle-spring-security6/src/test/java/waffle/spring/ImpersonateTest.java +++ b/Source/JNA/waffle-spring-security6/src/test/java/waffle/spring/ImpersonateTest.java @@ -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 @@ -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)); } } diff --git a/Source/JNA/waffle-tests-jakarta/src/test/java/waffle/servlet/ImpersonateTest.java b/Source/JNA/waffle-tests-jakarta/src/test/java/waffle/servlet/ImpersonateTest.java index 7c721235f8..f71bd994b2 100644 --- a/Source/JNA/waffle-tests-jakarta/src/test/java/waffle/servlet/ImpersonateTest.java +++ b/Source/JNA/waffle-tests-jakarta/src/test/java/waffle/servlet/ImpersonateTest.java @@ -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 @@ -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)); } } diff --git a/Source/JNA/waffle-tests-jakarta/src/test/java/waffle/windows/auth/WindowsAuthProviderTest.java b/Source/JNA/waffle-tests-jakarta/src/test/java/waffle/windows/auth/WindowsAuthProviderTest.java index 3dc6f5e983..4692cd1c53 100644 --- a/Source/JNA/waffle-tests-jakarta/src/test/java/waffle/windows/auth/WindowsAuthProviderTest.java +++ b/Source/JNA/waffle-tests-jakarta/src/test/java/waffle/windows/auth/WindowsAuthProviderTest.java @@ -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 @@ -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)); } } @@ -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)); } } diff --git a/Source/JNA/waffle-tests/src/test/java/waffle/servlet/ImpersonateTest.java b/Source/JNA/waffle-tests/src/test/java/waffle/servlet/ImpersonateTest.java index 8d51804827..10c8d3b5a0 100644 --- a/Source/JNA/waffle-tests/src/test/java/waffle/servlet/ImpersonateTest.java +++ b/Source/JNA/waffle-tests/src/test/java/waffle/servlet/ImpersonateTest.java @@ -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 @@ -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)); } } @@ -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(); @@ -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) { @@ -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"); @@ -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) { diff --git a/Source/JNA/waffle-tests/src/test/java/waffle/windows/auth/WindowsAuthProviderTest.java b/Source/JNA/waffle-tests/src/test/java/waffle/windows/auth/WindowsAuthProviderTest.java index 3dc6f5e983..bf8dbb5de4 100644 --- a/Source/JNA/waffle-tests/src/test/java/waffle/windows/auth/WindowsAuthProviderTest.java +++ b/Source/JNA/waffle-tests/src/test/java/waffle/windows/auth/WindowsAuthProviderTest.java @@ -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 @@ -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)); } } @@ -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)); } } @@ -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();