-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from intergral/cf-2023-windows-cfplugin-fix
fix(CFPlugin): fix CF server detection for CF 2023 Windows service
- Loading branch information
Showing
7 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (C) 2024 Intergral GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package coldfusion; | ||
|
||
public class Version { | ||
public static int getMajor() { | ||
if (System.getProperty("cf.test.error") != null) { | ||
throw new RuntimeException("failed to load version"); | ||
} | ||
return 10; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
plugins/cf-plugin/src/test/java/com/intergral/deep/plugin/cf/CFPluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (C) 2024 Intergral GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.intergral.deep.plugin.cf; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import com.intergral.deep.agent.api.plugin.EvaluationException; | ||
import com.intergral.deep.agent.api.plugin.ISnapshotContext; | ||
import com.intergral.deep.agent.api.resource.Resource; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
class CFPluginTest { | ||
|
||
@Test | ||
void canDecorate() throws EvaluationException { | ||
final CFPlugin cfPlugin = new CFPlugin(); | ||
final ISnapshotContext mock = Mockito.mock(ISnapshotContext.class); | ||
|
||
final Resource decorate = cfPlugin.decorate(null, mock); | ||
assertNotNull(decorate); | ||
assertEquals("10", decorate.getAttributes().get("cf_version")); | ||
assertNull(decorate.getAttributes().get("app_name")); | ||
|
||
Mockito.verify(mock).evaluateExpression("APPLICATION.applicationname"); | ||
} | ||
|
||
@Test | ||
void canHandleEvaluateDecorate() throws EvaluationException { | ||
final CFPlugin cfPlugin = new CFPlugin(); | ||
|
||
final ISnapshotContext mock = Mockito.mock(ISnapshotContext.class); | ||
|
||
Mockito.when(mock.evaluateExpression("APPLICATION.applicationname")).thenReturn("app_name"); | ||
|
||
final Resource decorate = cfPlugin.decorate(null, mock); | ||
assertNotNull(decorate); | ||
assertEquals("10", decorate.getAttributes().get("cf_version")); | ||
assertEquals("app_name", decorate.getAttributes().get("app_name")); | ||
|
||
Mockito.verify(mock).evaluateExpression("APPLICATION.applicationname"); | ||
} | ||
|
||
@Test | ||
void canHandleEvaluateFailedDecorate() throws EvaluationException { | ||
final CFPlugin cfPlugin = new CFPlugin(); | ||
|
||
final ISnapshotContext mock = Mockito.mock(ISnapshotContext.class); | ||
|
||
Mockito.when(mock.evaluateExpression("APPLICATION.applicationname")).thenThrow(new RuntimeException("test exception")); | ||
|
||
final Resource decorate = cfPlugin.decorate(null, mock); | ||
assertNotNull(decorate); | ||
assertEquals("10", decorate.getAttributes().get("cf_version")); | ||
assertNull(decorate.getAttributes().get("app_name")); | ||
|
||
Mockito.verify(mock).evaluateExpression("APPLICATION.applicationname"); | ||
} | ||
|
||
@Test | ||
void isActive() { | ||
assertFalse(new CFPlugin().isActive()); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
plugins/cf-plugin/src/test/java/com/intergral/deep/plugin/cf/UtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2024 Intergral GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.intergral.deep.plugin.cf; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junitpioneer.jupiter.ClearSystemProperty; | ||
import org.junitpioneer.jupiter.SetSystemProperty; | ||
|
||
class UtilsTest { | ||
|
||
@Test | ||
void canDetectNotCF() { | ||
assertFalse(Utils.isCFServer()); | ||
} | ||
|
||
@Test | ||
@ClearSystemProperty(key = "sun.java.command") | ||
void canHandleNoSunCommand() { | ||
assertFalse(Utils.isCFServer()); | ||
} | ||
|
||
@Test | ||
@SetSystemProperty(key = "coldfusion.home", value = "doesn't matter") | ||
void canDetectCFHome() { | ||
assertTrue(Utils.isCFServer()); | ||
} | ||
|
||
@Test | ||
@SetSystemProperty(key = "sun.java.command", value = "/some/coldfusion") | ||
void canUseSunCommand() { | ||
assertTrue(Utils.isCFServer()); | ||
} | ||
|
||
@Test | ||
void loadCFVersion() { | ||
assertEquals("10", Utils.loadCFVersion()); | ||
} | ||
|
||
@Test | ||
@SetSystemProperty(key = "cf.test.error", value = "anything") | ||
void failLoadCFVersion() { | ||
assertNull(Utils.loadCFVersion()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters