Skip to content

Commit

Permalink
Merge pull request #36 from mrFlick72/pipeline_test
Browse files Browse the repository at this point in the history
Pipeline test
  • Loading branch information
mrFlick72 authored Oct 19, 2022
2 parents ee06637 + 17ce631 commit 073277f
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 75 deletions.
76 changes: 40 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,51 @@
name: build vauthenticator
name: build VAuthenticator

on:
push: { }
workflow_dispatch: { }
workflow_dispatch:
inputs:
version:
description: 'make a tag'
required: false


jobs:
template-loading:
provisioning:
runs-on: ubuntu-20.04

steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: load templates on s3
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- run: |
TEMPLATES=("welcome.html" "mail-verify-challenge.html" "reset-password.html" "successful-mail-verify.html")
for TEMPLATE in ${TEMPLATES[@]}
do
aws s3 cp communication/default/mail/$TEMPLATE s3://${{ secrets.VAUTHENTICATOR_BUCKET }}/mail/templates/$TEMPLATE
done
provisioning:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- name: make an echo
run: |
echo version ${{github.event.inputs.version}}
- name: install node
uses: actions/setup-node@v3
with:
node-version: 16

- name: Set up JDK 17
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'corretto'

- name: build testing environment
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.13.5
- run: |
cd src/test/resources
docker-compose up &
sleep 80s
sudo chown -R $USER:$USER *
chmod 777 -R docker/dynamodb
run: |
export AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}
export AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}
export AWS_REGION=${{ secrets.AWS_REGION }}
aws s3api create-bucket --bucket bucket --endpoint http://localhost:4566 --region us-east-1
aws s3 cp index.html s3://bucket/mail/templates/welcome.html --endpoint http://localhost:4566 --region us-east-1
cd src/test/resources
docker-compose up &
sleep 80s
sudo chown -R $USER:$USER *
chmod 777 -R docker/dynamodb
- name: Build frontend artifacts
run: |
Expand All @@ -72,13 +59,30 @@ jobs:
- name: docker push
run: |
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
if [[ ${GITHUB_REF##*/} == 'master' ]]
then
DOCKER_TAG="latest"
else
DOCKER_TAG="${GITHUB_REF##*/}"
fi
echo "$DOCKER_TAG"
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
docker build . -t mrflick72/vauthenticator-k8s:$DOCKER_TAG
docker push mrflick72/vauthenticator-k8s:$DOCKER_TAG
- name: Create tag
if: github.event.inputs.version != '' || github.event.inputs.version != ' '

uses: ncipollo/release-action@v1
with:
tag: ${{github.event.inputs.version}}

- name: Docker tag
if: github.event.inputs.version != '' || github.event.inputs.version != ' '

run: |
DOCKER_TAG="${{github.event.inputs.version}}"
docker build . -t mrflick72/vauthenticator-k8s:$DOCKER_TAG
docker push mrflick72/vauthenticator-k8s:$DOCKER_TAG
25 changes: 25 additions & 0 deletions .github/workflows/template-loader.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: template loader

on:
workflow_dispatch: { }

jobs:
template-loading:
runs-on: ubuntu-20.04

steps:
- name: checkout
uses: actions/checkout@v3

- name: load templates on s3
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- run: |
TEMPLATES=("welcome.html" "mail-verify-challenge.html" "reset-password.html" "successful-mail-verify.html")
for TEMPLATE in ${TEMPLATES[@]}
do
aws s3 cp communication/default/mail/$TEMPLATE s3://${{ secrets.VAUTHENTICATOR_BUCKET }}/mail/templates/$TEMPLATE
done
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:17
FROM amazoncorretto:17.0.4

ADD target/vauthenticator.jar /usr/local/vauthenticator/

Expand Down
21 changes: 15 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<io.mockk.version>1.13.1</io.mockk.version>
<aws.sdk.version>2.17.276</aws.sdk.version>
<greenmail.version>1.6.10</greenmail.version>
<greenmail.version>1.6.11</greenmail.version>
<oauth2-authorization-server.version>0.3.1</oauth2-authorization-server.version>
<wiremock.version>2.27.2</wiremock.version>
</properties>
Expand Down Expand Up @@ -74,11 +74,6 @@
<version>4.1.1</version>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.6.1</version>
</dependency>

<dependency>
<groupId>com.hubspot.jinjava</groupId>
Expand Down Expand Up @@ -191,13 +186,27 @@
</dependencies>
</dependencyManagement>

<scm>
<connection>scm:git:${project.scm.url}</connection>
<developerConnection>scm:git:${project.scm.url}</developerConnection>
<url>[email protected]:mrFlick72/vauthenticator.git</url>
<tag>HEAD</tag>
</scm>

<build>
<finalName>vauthenticator</finalName>

<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>

<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<scmCommentPrefix>[ci skip]</scmCommentPrefix>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
35 changes: 17 additions & 18 deletions src/main/resources/templates/logout/oidc/global_logout.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<title>Global Logout from VAuthenticator...</title>
</head>
<body>
<script th:src="@{/webjars/jquery/3.0.0/jquery.js}"></script>

</body>
<div id="logoutBox">
Expand All @@ -14,37 +13,37 @@

<script th:inline="javascript">
/*<![CDATA[*/
var federatedServers = [[${federatedServers}]];
var logoutIframe = $("<iframe ></iframe>")
let federatedServers = [[${federatedServers}]];
let logoutIframe = document.createElement("iframe")

function newLogoutIFrame(logoutUrl) {
var clone = logoutIframe.clone();
clone.attr("src", logoutUrl);
clone.attr("style", "visibility: hidden;");
const newLogoutIFrame = (logoutUrl) => {
let clone = logoutIframe.cloneNode(true);
clone.setAttribute("src", logoutUrl);
clone.setAttribute("style", "visibility: hidden;");
return clone;
}

federatedServers
.forEach(function (logoutUrl) {
$("#logoutBox")
.forEach((logoutUrl) => {
document.querySelector("#logoutBox")
.append(newLogoutIFrame(logoutUrl));
})

var getParams = function (url) {
var params = {};
var parser = document.createElement('a');
let getParams = (url) => {
let params = {};
let parser = document.createElement('a');
parser.href = url;
var query = parser.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
let query = parser.search.substring(1);
let lets = query.split('&');
for (let i = 0; i < lets.length; i++) {
let pair = lets[i].split('=');
params[pair[0]] = decodeURIComponent(pair[1]);
}
return params;
};

var params = getParams(window.location.href);
var redirectUri = params["post_logout_redirect_uri"];
let params = getParams(window.location.href);
let redirectUri = params["post_logout_redirect_uri"];

setInterval(function (){
console.log("redirectUri: " + redirectUri)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/session/management.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="/webjars/crypto-js/3.1.9-1/crypto-js.js"></script>
<script src="/webjars/crypto-js/4.1.1/crypto-js.js"></script>
<meta charset="UTF-8">
<title>OP Session Management Checker IFrame</title>
</head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
package it.valeriovaudi.vauthenticator.document

import it.valeriovaudi.vauthenticator.support.DocumentUtils.initDocumentTests
import it.valeriovaudi.vauthenticator.support.DocumentUtils.s3Client
import it.valeriovaudi.vauthenticator.support.TestingFixture.loadFileFor
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.s3.S3Client.builder
import java.net.URI

internal class S3DocumentRepositoryTest {

@Test
internal fun `load document from S3`() {

val s3Client = builder()
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("xxxx", "xxx")))
.endpointOverride(URI.create("http://localhost:4566"))
.region(Region.US_EAST_1)
.build()
initDocumentTests(s3Client)

val documentRepository = S3DocumentRepository(s3Client, "bucket")
val document = documentRepository.loadDocument("mail", "templates/welcome.html")

val expected = loadFileFor("index.html")
Assertions.assertEquals(expected, String(document))
assertEquals(expected, String(document))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package it.valeriovaudi.vauthenticator.support

import org.springframework.core.io.ClassPathResource
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
import software.amazon.awssdk.core.sync.RequestBody
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.s3.model.CreateBucketRequest
import software.amazon.awssdk.services.s3.model.PutObjectRequest
import java.net.URI


object DocumentUtils {
private const val documentBucket: String = "bucket"

val s3Client: S3Client = S3Client.builder()
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create("ACCESS_KEY_ID", "SECRET_ACCESS_KEY"))
).region(Region.US_EAST_1)
.endpointOverride(URI.create("http://localhost:4566"))
.build()

fun initDocumentTests(client: S3Client) {
try {
client.createBucket(
CreateBucketRequest.builder()
.bucket(documentBucket)
.build()
)
}catch (e : Exception){

}

client.putObject(
PutObjectRequest.builder()
.bucket(documentBucket)
.key("mail/templates/welcome.html")
.build(),
RequestBody.fromFile(ClassPathResource("index.html").file)
)
}

}

0 comments on commit 073277f

Please sign in to comment.