Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions acs-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@
<argLine/>
<systemPropertyVariables>
<ZAC_UAA_URL>${ZAC_UAA_URL}</ZAC_UAA_URL>
<spring.profiles.active>h2,predix,simple-cache</spring.profiles.active>
<spring.profiles.active>h2,predix,simple-cache,httpValidation</spring.profiles.active>
</systemPropertyVariables>
<excludes>
<exclude>**/ACSPerformanceIT.java</exclude>
Expand Down Expand Up @@ -658,8 +658,53 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.ge.predix.eventhub</groupId>
<artifactId>predix-event-hub-sdk</artifactId>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anubhavi25, why are you adding these dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're the same Audit-related dependencies and exclusions as the predix-local profile above it and are necessary so that Maven Enforcer doesn't crib when running integration tests against the predix-local-titan profile

<version>1.2.2-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</exclusion>
<exclusion>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -672,7 +717,7 @@
<argLine/>
<systemPropertyVariables>
<ZAC_UAA_URL>${ZAC_UAA_URL}</ZAC_UAA_URL>
<spring.profiles.active>h2,predix,simple-cache,titan</spring.profiles.active>
<spring.profiles.active>h2,predix,simple-cache,titan,httpValidation</spring.profiles.active>
</systemPropertyVariables>
<excludes>
<exclude>**/ACSPerformanceIT.java</exclude>
Expand Down Expand Up @@ -769,7 +814,7 @@
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<environmentVariables>
<SPRING_PROFILES_ACTIVE>h2,public,simple-cache</SPRING_PROFILES_ACTIVE>
<SPRING_PROFILES_ACTIVE>h2,public,simple-cache,httpValidation</SPRING_PROFILES_ACTIVE>
<management.health.redis.enabled>false</management.health.redis.enabled>
<uaaCheckHealthUrl>${ACS_UAA_URL}/healthz</uaaCheckHealthUrl>
<cors.xhr.allowed.headers>Origin,Accept,X-Requested-With,Content-Type,Access-Control-Request-Method, Access-Control-Request-Headers</cors.xhr.allowed.headers>
Expand Down Expand Up @@ -878,7 +923,7 @@
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<environmentVariables>
<SPRING_PROFILES_ACTIVE>h2,public,simple-cache,titan</SPRING_PROFILES_ACTIVE>
<SPRING_PROFILES_ACTIVE>h2,public,simple-cache,titan,httpValidation</SPRING_PROFILES_ACTIVE>
<management.health.redis.enabled>false</management.health.redis.enabled>
<uaaCheckHealthUrl>${ACS_UAA_URL}/healthz</uaaCheckHealthUrl>
<cors.xhr.allowed.headers>Origin,Accept,X-Requested-With,Content-Type,Access-Control-Request-Method, Access-Control-Request-Headers</cors.xhr.allowed.headers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
import java.io.IOException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.test.context.ContextConfiguration;
Expand All @@ -39,6 +42,7 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.ge.predix.acs.commons.web.AcsApiUriTemplates;
import com.ge.predix.acs.model.Attribute;
import com.ge.predix.acs.model.Effect;
import com.ge.predix.acs.rest.BaseResource;
Expand All @@ -62,6 +66,9 @@ public class ACSAcceptanceIT extends AbstractTestNGSpringContextTests {
@Value("${ACS_URL}")
private String acsBaseUrl;

@Autowired
private Environment environment;

@Autowired
private ZoneHelper zoneHelper;

Expand Down Expand Up @@ -107,8 +114,8 @@ public void testAcsHealth() {

RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<String> heartbeatResponse = restTemplate
.exchange(this.acsBaseUrl + "/monitoring/heartbeat", HttpMethod.GET,
ResponseEntity<String> heartbeatResponse =
restTemplate.exchange(this.acsBaseUrl + AcsApiUriTemplates.HEARTBEAT_URL, HttpMethod.GET,
new HttpEntity<>(this.headersWithZoneSubdomain), String.class);
Assert.assertEquals(heartbeatResponse.getBody(), "alive", "ACS Heartbeat Check Failed");
} catch (Exception e) {
Expand Down Expand Up @@ -154,11 +161,11 @@ public void testCompleteACSFlow(final String endpoint, final HttpHeaders headers
BaseResource resource = new BaseResource();
resource.setResourceIdentifier("/alarms/sites/sanramon");

testResource = this.privilegeHelper
.putResource(this.acsZoneRestTemplate, resource, endpoint, headers, region);
testResource =
this.privilegeHelper.putResource(this.acsZoneRestTemplate, resource, endpoint, headers, region);

ResponseEntity<PolicyEvaluationResult> evalResponse = this.acsZoneRestTemplate
.postForEntity(endpoint + PolicyHelper.ACS_POLICY_EVAL_API_PATH,
ResponseEntity<PolicyEvaluationResult> evalResponse =
this.acsZoneRestTemplate.postForEntity(endpoint + PolicyHelper.ACS_POLICY_EVAL_API_PATH,
new HttpEntity<>(policyEvalRequest, headers), PolicyEvaluationResult.class);

Assert.assertEquals(evalResponse.getStatusCode(), HttpStatus.OK);
Expand All @@ -167,16 +174,15 @@ public void testCompleteACSFlow(final String endpoint, final HttpHeaders headers
} finally {
// delete policy
if (null != testPolicyName) {
this.acsZoneRestTemplate
.exchange(endpoint + PolicyHelper.ACS_POLICY_SET_API_PATH + testPolicyName, HttpMethod.DELETE,
new HttpEntity<>(headers), String.class);
this.acsZoneRestTemplate.exchange(endpoint + PolicyHelper.ACS_POLICY_SET_API_PATH + testPolicyName,
HttpMethod.DELETE, new HttpEntity<>(headers), String.class);
}

// delete attributes
if (null != marissa) {
this.acsZoneRestTemplate
.exchange(endpoint + PrivilegeHelper.ACS_SUBJECT_API_PATH + marissa.getSubjectIdentifier(),
HttpMethod.DELETE, new HttpEntity<>(headers), String.class);
this.acsZoneRestTemplate.exchange(
endpoint + PrivilegeHelper.ACS_SUBJECT_API_PATH + marissa.getSubjectIdentifier(),
HttpMethod.DELETE, new HttpEntity<>(headers), String.class);
}
if (null != testResource) {
String encodedResource = URLEncoder.encode(testResource.getResourceIdentifier(), "UTF-8");
Expand All @@ -188,12 +194,27 @@ public void testCompleteACSFlow(final String endpoint, final HttpHeaders headers

@DataProvider(name = "endpointProvider")
public Object[][] getAcsEndpoint() throws Exception {
PolicyEvaluationRequestV1 policyEvalForBob = this.policyHelper
.createEvalRequest("GET", "bob", "/alarms/sites/sanramon", null);
PolicyEvaluationRequestV1 policyEvalForBob =
this.policyHelper.createEvalRequest("GET", "bob", "/alarms/sites/sanramon", null);

return new Object[][] { { this.acsBaseUrl, this.headersWithZoneSubdomain, policyEvalForBob, "bob" } };
}

// TODO: Remove this test when the "httpValidation" Spring profile is removed
@Test
public void testHttpValidationBasedOnActiveSpringProfile() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);

ResponseEntity<String> response =
new RestTemplate().exchange(URI.create(this.acsBaseUrl + AcsApiUriTemplates.HEARTBEAT_URL),
HttpMethod.GET, new HttpEntity<>(headers), String.class);
Assert.assertEquals(response.getStatusCode(),
(Arrays.asList(this.environment.getActiveProfiles()).contains("httpValidation")
? HttpStatus.OK : HttpStatus.NOT_ACCEPTABLE));
}

@AfterClass
public void tearDown() {
this.zoneHelper.deleteZone(this.acsAdminRestTemplate, this.acsZoneName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.util.MimeType;
Expand All @@ -25,6 +27,8 @@
public abstract class AbstractHttpMethodsFilter extends OncePerRequestFilter {

private final Map<String, Set<HttpMethod>> uriPatternsAndAllowedHttpMethods;

private static final Logger LOGGER_INSTANCE = LoggerFactory.getLogger(AbstractHttpMethodsFilter.class);
private static final Set<MimeType> ACCEPTABLE_MIME_TYPES =
new HashSet<>(Arrays.asList(MimeTypeUtils.ALL, MimeTypeUtils.APPLICATION_JSON, MimeTypeUtils.TEXT_PLAIN));

Expand Down Expand Up @@ -85,6 +89,7 @@ protected void doFilterInternal(final HttpServletRequest request, final HttpServ
}
}
if (!foundAcceptableMimeType) {
LOGGER_INSTANCE.error("Malformed Accept header sent in request: {}", acceptHeaderValue);
sendNotAcceptableError(response);
return;
}
Expand Down
4 changes: 3 additions & 1 deletion service/start-acs-postgres-predix-titan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
# 4. execute: 'create user postgres;'
# 5. execute: 'grant all privileges on database acs to postgres;'

export SPRING_PROFILES_ACTIVE='envDbConfig,predix,simple-cache,titan'
if [[ -z "$SPRING_PROFILES_ACTIVE" ]]; then
export SPRING_PROFILES_ACTIVE='envDbConfig,predix,simple-cache,titan'
fi
export DB_DRIVER_CLASS_NAME='org.postgresql.Driver'
export DB_URL='jdbc:postgresql:acs'
export DB_USERNAME='postgres'
Expand Down
4 changes: 3 additions & 1 deletion service/start-acs-postgres-predix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
# 4. execute: 'create user postgres;'
# 5. execute: 'grant all privileges on database acs to postgres;'

export SPRING_PROFILES_ACTIVE='envDbConfig,predix,simple-cache'
if [[ -z "$SPRING_PROFILES_ACTIVE" ]]; then
export SPRING_PROFILES_ACTIVE='envDbConfig,predix,simple-cache'
fi
export DB_DRIVER_CLASS_NAME='org.postgresql.Driver'
export DB_URL='jdbc:postgresql:acs'
export DB_USERNAME='postgres'
Expand Down
18 changes: 10 additions & 8 deletions service/start-acs-postgres.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env bash

#*******************************************************************************
# Copyright 2016 General Electric Company.
# Copyright 2016 General Electric Company.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************

Expand All @@ -23,7 +23,9 @@
# 4. execute: 'create user postgres;'
# 5. execute: 'grant all privileges on database acs to postgres;'

export SPRING_PROFILES_ACTIVE='envDbConfig,public,simple-cache'
if [[ -z "$SPRING_PROFILES_ACTIVE" ]]; then
export SPRING_PROFILES_ACTIVE='envDbConfig,public,simple-cache'
fi
export DB_DRIVER_CLASS_NAME='org.postgresql.Driver'
export DB_URL='jdbc:postgresql:acs'
export DB_USERNAME='postgres'
Expand Down
18 changes: 10 additions & 8 deletions service/start-acs-predix-titan.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/usr/bin/env bash

#*******************************************************************************
# Copyright 2016 General Electric Company.
# Copyright 2016 General Electric Company.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************

export SPRING_PROFILES_ACTIVE='h2,predix,simple-cache,titan'
if [[ -z "$SPRING_PROFILES_ACTIVE" ]]; then
export SPRING_PROFILES_ACTIVE='h2,predix,simple-cache,titan'
fi
export DIR=$( dirname "$( python -c "import os; print os.path.abspath('${BASH_SOURCE[0]}')" )" )
source "${DIR}/start-acs.sh" "$@"
18 changes: 10 additions & 8 deletions service/start-acs-predix.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/usr/bin/env bash

#*******************************************************************************
# Copyright 2016 General Electric Company.
# Copyright 2016 General Electric Company.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************

export SPRING_PROFILES_ACTIVE='h2,predix,simple-cache'
if [[ -z "$SPRING_PROFILES_ACTIVE" ]]; then
export SPRING_PROFILES_ACTIVE='h2,predix,simple-cache'
fi
export DIR=$( dirname "$( python -c "import os; print os.path.abspath('${BASH_SOURCE[0]}')" )" )
source "${DIR}/start-acs.sh" "$@"
19 changes: 11 additions & 8 deletions service/start-acs-public-titan.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#!/usr/bin/env bash

#*******************************************************************************
# Copyright 2016 General Electric Company.
# Copyright 2016 General Electric Company.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************

unset PROXY_OPTS
export SPRING_PROFILES_ACTIVE='h2,public,simple-cache,titan'

if [[ -z "$SPRING_PROFILES_ACTIVE" ]]; then
export SPRING_PROFILES_ACTIVE='h2,public,simple-cache,titan'
fi
export DIR=$( dirname "$( python -c "import os; print os.path.abspath('${BASH_SOURCE[0]}')" )" )
source "${DIR}/start-acs.sh" "$@"
Loading