-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Jenkins-39822] GitHub plugin functional tests broken against 1.651+ (#…
…157) * [JENKINS-39822] Fix SECURITY-170 issues * [JENKINS-39822] Make sure there is always BuildData on testNoBuildRevision * [JENKINS-39822] Use conditional on plugin version * This way we change behaviour only if needed * [JENKINS-39822] Conditionally handle SECURITY-170 * [JENKINS-39822] Invoke build getting into account git plugin version * Git plugin 2.4.1+ does not include BuildData if checkout fails, resulting in testNoBuildRevision failing * [JENKINS-39822] Fix style * [JENKINS-39822] Added javadoc and more clarifying comments * [JENKINS-39822] Fix codacy warning
- Loading branch information
Showing
3 changed files
with
93 additions
and
1 deletion.
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
61 changes: 61 additions & 0 deletions
61
src/test/java/org/jenkinsci/plugins/github/common/ParametersActionHelper.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,61 @@ | ||
package org.jenkinsci.plugins.github.common; | ||
|
||
import hudson.model.ParametersAction; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
|
||
/** | ||
* Helper class to check if the environment includes SECURITY-170 fix | ||
* | ||
* @see <a href=https://wiki.jenkins-ci.org/display/JENKINS/Plugins+affected+by+fix+for+SECURITY-170</a> | ||
*/ | ||
public class ParametersActionHelper { | ||
|
||
private static final Class<ParametersAction> actionClass = ParametersAction.class; | ||
|
||
private boolean hasSafeParameterConfig = false; | ||
private boolean abletoInspect = true; | ||
private static final String UNDEFINED_PARAMETERS_FIELD_NAME = "KEEP_UNDEFINED_PARAMETERS_SYSTEM_PROPERTY_NAME"; | ||
private static final String SAFE_PARAMETERS_FIELD_NAME = "SAFE_PARAMETERS_SYSTEM_PROPERTY_NAME"; | ||
|
||
public ParametersActionHelper() { | ||
try { | ||
for (Field field : actionClass.getDeclaredFields()) { | ||
if (Modifier.isStatic(field.getModifiers()) && isSafeParamsField(field)) { | ||
this.hasSafeParameterConfig = true; | ||
break; | ||
} | ||
} | ||
} catch (Exception e) { | ||
this.abletoInspect = false; | ||
} | ||
} | ||
|
||
/** | ||
* Method to check if the fix for SECURITY-170 is present | ||
* | ||
* @return true if the SECURITY-170 fix is present, false otherwise | ||
*/ | ||
public boolean getHasSafeParameterConfig() { | ||
return hasSafeParameterConfig; | ||
} | ||
|
||
/** | ||
* Method to check if this class has been able to determine the existence of SECURITY-170 fix | ||
* | ||
* @return true if the check for SECURITY-170 has been executed (whatever the result) false otherwise | ||
*/ | ||
public boolean getAbletoInspect() { | ||
return abletoInspect; | ||
} | ||
|
||
private boolean isSafeParamsField(Field field) { | ||
String fieldName = field.getName(); | ||
return UNDEFINED_PARAMETERS_FIELD_NAME.equals(fieldName) | ||
|| SAFE_PARAMETERS_FIELD_NAME.equals(fieldName); | ||
} | ||
|
||
|
||
|
||
} |