Skip to content

Commit

Permalink
Merge pull request #45 from UWIT-IAM/everything
Browse files Browse the repository at this point in the history
Port all the changes from cert-service into spregistry
  • Loading branch information
stea-uw authored Oct 30, 2023
2 parents 8f153dc + 8250ce4 commit 08ba1ac
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 79 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improvethe workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
token: ${{ secrets.ACTIONS_PAT }}
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn --no-transfer-progress clean compile test package
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/velocity-spring"]
path = deps/velocity-spring
url = https://github.com/UWIT-IAM/velocity-spring.git
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://pre-commit.com/ for file specification
#
# These checks are not performed by default. If you'd like to use these checks,
# install pre-commit and then run `pre-commit install` in the root of your
# repository.

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
# Avoid trailing whitespace, see Java style guide
- id: trailing-whitespace

# Avoid files without newline ending, see Java style guide
- id: end-of-file-fixer

# Verify modified data files
- id: check-yaml
- id: check-xml

- repo: https://github.com/ejba/pre-commit-maven
rev: v0.3.3
hooks:
# Project compiles and passes unit tests
- id: maven-compile
- id: maven-test
38 changes: 0 additions & 38 deletions README.dependencies

This file was deleted.

12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,31 @@ The application is quite specific to resources at the University, such as a DNS

Create spreg.properties.dev and spreg.properties.prod from spreg.properties.tmpl

```
```
## Dependencies

See README.dependencies for information on a special step needed to prepare dependencies for the build.

```
## Build

```
$> mvn clean compile package
```

```
## Install

```
$> cd ansible
see the README for configuration steps
# see the README for configuration steps
$> ./install.sh -h (target)
```

```
## IdP install

```
$> cd idp-tools
see the README for configuration steps
$> ./install.sh -h (target)
```

1 change: 1 addition & 0 deletions deps/velocity-spring
Submodule velocity-spring added at b8b1c3
61 changes: 48 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.washington.iam</groupId>
<artifactId>spreg</artifactId>
Expand All @@ -11,7 +11,7 @@
<repository>
<id>apache</id>
<name>apache</name>
<url>http://maven.apache.org</url>
<url>https://maven.apache.org</url>
</repository>
</repositories>
<dependencies>
Expand All @@ -21,6 +21,11 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
Expand All @@ -39,13 +44,13 @@
<artifactId>javers-core</artifactId>
<version>6.6.5</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<!--
<!--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-reload4j</artifactId>
Expand Down Expand Up @@ -129,16 +134,18 @@
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>velocity-tools</groupId>
<artifactId>velocity-tools-view</artifactId>
<version>1.4</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>spring-velocity-support</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>edu.washington.iam</groupId>
<artifactId>uw-spring-velocity-web</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand All @@ -157,9 +164,9 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
</dependencies>
<build>
Expand All @@ -173,6 +180,34 @@
<target>1.8</target>
</configuration>
</plugin>

<!-- Explicity specify war version to avoid unexpected build errors. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>

<!-- Compile spring-velocity from source -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>./deps/velocity-spring/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>spreg</finalName>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:test-db-context.xml")
public class DBFilterPolicyDAOTest {
/**
* Amount of time for tests to sleep waiting for DB operations.
*
* Set as low as possible.
*/
private static int SLEEP_DELAY_MS = 10;

private final Logger log = LoggerFactory.getLogger(getClass());

@Autowired
Expand Down Expand Up @@ -96,6 +103,7 @@ public void testGetFilterPoliciesCaching() throws Exception {
// get it again to test that update check works
afps = dao.getFilterPolicies(filterPolicyGroup);
Assert.assertEquals(fakeEntityIds.size(), afps.size());

NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update("delete from filter where entity_id in (:entityIds)",
new MapSqlParameterSource().addValue("entityIds", fakeEntityIds));
Expand Down Expand Up @@ -200,7 +208,7 @@ public void testCreateFilterPolicy() throws Exception {
// check that there's nothing in there already
Assert.assertEquals(0, qResults.size());
Timestamp preUpdateTime = new Timestamp(new Date().getTime());
Thread.sleep(500);
Thread.sleep(SLEEP_DELAY_MS);
attributeFilterPolicy.setUuid(genUUID());
dao.createFilterPolicy(filterPolicyGroup, attributeFilterPolicy, remoteUser);

Expand Down Expand Up @@ -228,7 +236,7 @@ public void testCreateFilterPolicyPreviouslyDeleted() throws Exception {
, Timestamp.class);
Assert.assertEquals(0, qResults.size());
Timestamp preUpdateTime = new Timestamp(new Date().getTime());
Thread.sleep(500);
Thread.sleep(SLEEP_DELAY_MS);
dao.updateFilterPolicies(filterPolicyGroup, Arrays.asList(attributeFilterPolicy), remoteUser);

qResults = template.queryForList("select start_time from filter where entity_id = ? and end_time is null"
Expand All @@ -255,7 +263,7 @@ public void testUpdateFilterPolicy() throws Exception {
Assert.assertEquals(1, qResults.size());
Timestamp preUpdateTime = qResults.get(0);
//it's too fast!
Thread.sleep(500);
Thread.sleep(SLEEP_DELAY_MS);
dao.updateFilterPolicy(filterPolicyGroup, attributeFilterPolicy, remoteUser);

qResults = template.queryForList("select start_time from filter where entity_id = ? and end_time is null"
Expand Down Expand Up @@ -283,25 +291,21 @@ public void testUpdateFilterPolicies() throws Exception {
, new MapSqlParameterSource().addValue("ids", entityIds)
, Timestamp.class);
Assert.assertEquals(2, qResults.size());
Timestamp preUpdateTime = new Timestamp(new Date().getTime());
Thread.sleep(500);
Thread.sleep(SLEEP_DELAY_MS);

List<AttributeFilterPolicy> updatePolicies = new ArrayList<>();
updatePolicies.add(fakeAttributeFilterPolicy(filterPolicyGroup, updateEntityId));
updatePolicies.add(fakeAttributeFilterPolicy(filterPolicyGroup, createEntityId));

dao.updateFilterPolicies(filterPolicyGroup, updatePolicies, remoteUser);

qResults = namedTemplate.queryForList("select start_time from filter where end_time is null and entity_id in (:ids)"
// The two updated policies should have later start_times than other one
qResults = namedTemplate.queryForList(
"select start_time from filter where end_time is null and entity_id in (:ids)" +
" and start_time > (select min(start_time) from filter where end_time is null)"
, new MapSqlParameterSource().addValue("ids", entityIds)
, Timestamp.class);
Assert.assertEquals(3, qResults.size());
int updateCount = 0;
for(Timestamp result : qResults){
if(result.after(preUpdateTime))
updateCount++;
}
Assert.assertEquals(2, updateCount);
Assert.assertEquals(2, qResults.size());

//clean up
namedTemplate.update("delete from filter where entity_id in (:ids)",
Expand Down Expand Up @@ -359,6 +363,9 @@ private void setupWithRPs(List<String> entityIds){
"values (?, ?, ?, ?, ?, now())",
genUUID(), groupId, entityId, fakeRelyingPartyXml(entityId), null);
}

// All tests expect filter to be empty at start.
template.update("delete from filter");
}

private void teardownRPs(List<String> entityIds){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/test-db-context.xml")
@ContextConfiguration("classpath:test-db-context.xml")
public class ProxyManagerDBTest {
/* Integration tests commented out to placate CI */
@Autowired
Expand Down
30 changes: 30 additions & 0 deletions src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<configuration>


<appender name="SP_LOGS" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>target/test.log</File>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Unused during tests, files unlikely to roll over -->
<FileNamePattern>target/test-%d{yyyy-MM-dd}.log</FileNamePattern>
</rollingPolicy>

<layout class="ch.qos.logback.classic.PatternLayout">
<!-- General logging pattern -->
<Pattern>%date{HH:mm:ss.SSS} %level [%logger:%line] - %msg%n %ex{1}</Pattern>
</layout>

</appender>

<root>
<level value="ERROR" />
<appender-ref ref="SP_LOGS" />
</root>

<logger name="edu.washington">
<level value="INFO"/>
</logger>



</configuration>
Loading

0 comments on commit 08ba1ac

Please sign in to comment.