-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
666 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# For most projects, this workflow file will not need changing; you simply need | ||
# to commit it to your repository. | ||
# | ||
# You may wish to alter this file to override the set of languages analyzed, | ||
# or to provide custom queries or build logic. | ||
# | ||
# ******** NOTE ******** | ||
# We have attempted to detect the languages in your repository. Please check | ||
# the `language` matrix defined below to confirm you have the correct set of | ||
# supported CodeQL languages. | ||
# | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ develop, gh-pages, master ] | ||
pull_request: | ||
# The branches below must be a subset of the branches above | ||
branches: [ develop ] | ||
schedule: | ||
- cron: '41 1 * * 6' | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ 'java', 'javascript' ] | ||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] | ||
# Learn more: | ||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v1 | ||
with: | ||
languages: ${{ matrix.language }} | ||
# If you wish to specify custom queries, you can do so here or in a config file. | ||
# By default, queries listed here will override any specified in a config file. | ||
# Prefix the list here with "+" to use these queries and those in the config file. | ||
# queries: ./path/to/local/query, your-org/your-repo/queries@main | ||
|
||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). | ||
# If this step fails, then you should remove it and run the build manually (see below) | ||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v1 | ||
|
||
# ℹ️ Command-line programs to run using the OS shell. | ||
# 📚 https://git.io/JvXDl | ||
|
||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines | ||
# and modify them (or add more) to build your code if your project | ||
# uses a compiled language | ||
|
||
#- run: | | ||
# make bootstrap | ||
# make release | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v1 |
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,5 @@ | ||
# Security Policy | ||
|
||
## Reporting a Vulnerability | ||
|
||
Please create an issue and provide details like the attack vector or examples for exploitation. |
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
69 changes: 69 additions & 0 deletions
69
api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/GStringConverter.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,69 @@ | ||
package de.valtech.aecu.api.groovy.console.bindings; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import groovy.lang.GString; | ||
|
||
/** | ||
* Converts GString to String. | ||
* | ||
* @author Roland Gruber | ||
*/ | ||
public class GStringConverter { | ||
|
||
private GStringConverter() { | ||
// no instantiation | ||
} | ||
|
||
/** | ||
* Converts the input in case it is a GString. | ||
* | ||
* @param input input | ||
* @return converted value | ||
*/ | ||
public static Object convert(Object input) { | ||
if (input instanceof GString) { | ||
return ((GString) input).toString(); | ||
} | ||
return input; | ||
} | ||
|
||
/** | ||
* Converts the input in case it is a GString. | ||
* | ||
* @param input input | ||
* @return converted value | ||
*/ | ||
public static Map<String, Object> convert(Map<String, Object> input) { | ||
if (input == null) { | ||
return input; | ||
} | ||
Map<String, Object> output = new HashMap<>(input); | ||
for (Map.Entry<String, Object> entry : input.entrySet()) { | ||
if (entry.getValue() instanceof GString) { | ||
output.put(entry.getKey(), convert(entry.getValue())); | ||
} | ||
} | ||
return output; | ||
} | ||
|
||
/** | ||
* Converts the input in case it is a GString. | ||
* | ||
* @param input input | ||
* @return converted value | ||
*/ | ||
public static Object[] convert(Object[] input) { | ||
if (input == null) { | ||
return input; | ||
} | ||
Object[] output = Arrays.copyOf(input, input.length); | ||
for (int i = 0; i < output.length; i++) { | ||
output[i] = convert(output[i]); | ||
} | ||
return output; | ||
} | ||
|
||
} |
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
106 changes: 106 additions & 0 deletions
106
...valtech/aecu/core/groovy/console/bindings/filters/FilterByMultiValuePropContainsTest.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,106 @@ | ||
/* | ||
* Copyright 2020 Valtech GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package de.valtech.aecu.core.groovy.console.bindings.filters; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.api.resource.ValueMap; | ||
import org.codehaus.groovy.runtime.GStringImpl; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByMultiValuePropContains; | ||
import groovy.lang.GString; | ||
|
||
/** | ||
* Tests FilterByMultiValuePropContains | ||
* | ||
* @author Roland Gruber | ||
* | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class FilterByMultiValuePropContainsTest { | ||
|
||
private static final String NAME1 = "name"; | ||
private static final String VALUE1 = "value"; | ||
private static final String NAME2 = "name2"; | ||
private static final String VALUE2 = "value2"; | ||
private static final String NAME3 = "name3"; | ||
private static final GString VALUE_G = new GStringImpl(new Object[] {2}, new String[] {"value"}); | ||
|
||
@Mock | ||
private Resource resource; | ||
|
||
@Mock | ||
ValueMap values; | ||
|
||
@Before | ||
public void setup() { | ||
when(resource.getValueMap()).thenReturn(values); | ||
when(values.get(NAME1)).thenReturn(new Object[] {VALUE1, VALUE2}); | ||
when(values.get(NAME2)).thenReturn(new Object[] {VALUE2}); | ||
} | ||
|
||
@Test | ||
public void filterAttributeNull_filterValueEmpty() { | ||
Object[] filterAttributes = new Object[0]; | ||
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME1, filterAttributes); | ||
|
||
assertTrue(filter.filter(resource, new StringBuilder())); | ||
} | ||
|
||
@Test | ||
public void filterAttributeNull_filterValueNonNull() { | ||
Object[] filterAttributes = new Object[] {VALUE1}; | ||
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME3, filterAttributes); | ||
|
||
assertFalse(filter.filter(resource, new StringBuilder())); | ||
} | ||
|
||
@Test | ||
public void filterAttributeNonNull_filterValueNonNull() { | ||
Object[] filterAttributes = new Object[] {VALUE1}; | ||
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME1, filterAttributes); | ||
|
||
assertTrue(filter.filter(resource, new StringBuilder())); | ||
} | ||
|
||
@Test | ||
public void filterAttributeNonNull_filterValueMulti() { | ||
Object[] filterAttributes = new Object[] {VALUE1, VALUE2}; | ||
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME1, filterAttributes); | ||
|
||
assertTrue(filter.filter(resource, new StringBuilder())); | ||
} | ||
|
||
@Test | ||
public void filterAttributeGString() { | ||
Object[] filterAttributes = new Object[] {VALUE_G}; | ||
FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME2, filterAttributes); | ||
|
||
assertTrue(filter.filter(resource, new StringBuilder())); | ||
} | ||
|
||
} |
Oops, something went wrong.