Skip to content

Commit

Permalink
fix: add fusion csrf cookie to correct path (#11852)
Browse files Browse the repository at this point in the history
* fix: add fusion csrf cookie to correct path

* code format
  • Loading branch information
haijian-vaadin committed Sep 15, 2021
1 parent 204e5dc commit 00226c1
Show file tree
Hide file tree
Showing 12 changed files with 454 additions and 1 deletion.
2 changes: 2 additions & 0 deletions flow-tests/pom.xml
Expand Up @@ -335,6 +335,8 @@
<module>test-ccdm/pom-production.xml</module>
<module>test-ccdm-flow-navigation</module>
<module>test-ccdm-flow-navigation/pom-production.xml</module>
<module>test-fusion-csrf</module>
<module>test-fusion-csrf-context</module>

<module>test-root-context</module>

Expand Down
3 changes: 3 additions & 0 deletions flow-tests/test-fusion-csrf-context/.gitignore
@@ -0,0 +1,3 @@

# /
frontend
151 changes: 151 additions & 0 deletions flow-tests/test-fusion-csrf-context/pom.xml
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.vaadin</groupId>
<artifactId>flow-tests</artifactId>
<version>9.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>test-fusion-csrf-context</artifactId>
<name>Fusion CSRF tests with custom context path</name>
<description>
For https://github.com/vaadin/fusion/issues/105.
It verifies that the csrf cookie is added to correct path
when first open a sub view.
Note, the test needs to be in a separate module because
it needs to open a sub view first, put the test into another
module cannot gurantee this.
</description>
<version>9.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<!-- Project dependencies -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>fusion-endpoint</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dev-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>test-fusion-csrf</artifactId>
<version>${project.version}</version>
<classifier>frontend</classifier>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>test-fusion-csrf</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.vaadin</groupId>
<artifactId>test-fusion-csrf</artifactId>
<version>${project.version}</version>
<classifier>frontend</classifier>
<outputDirectory>${project.basedir}/frontend</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- This module is mapped to default web context -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<systemProperties>
<systemProperty>
<!-- make sure we do not leave webpack-dev-server running after IT -->
<name>vaadin.reuseDevServer</name>
<value>false</value>
</systemProperty>
</systemProperties>
<webApp>
<contextPath>/foo</contextPath>
</webApp>
</configuration>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>flow-maven-plugin</artifactId>
<configuration>
<productionMode>false</productionMode>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>local-run</id>
<activation>
<property>
<name>!test.use.hub</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin
</artifactId>
<version>
${driver.binary.downloader.maven.plugin.version}
</version>
<configuration>
<onlyGetDriversForHostOperatingSystem>true
</onlyGetDriversForHostOperatingSystem>
<rootStandaloneServerDirectory>
${project.rootdir}/driver
</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>
${project.rootdir}/driver_zips
</downloadedZipFileDirectory>
<customRepositoryMap>
${project.rootdir}/drivers.xml
</customRepositoryMap>
</configuration>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
@@ -0,0 +1,10 @@
package com.vaadin.fusion.csrftest;

import javax.servlet.annotation.WebServlet;

import com.vaadin.flow.server.VaadinServlet;

@WebServlet("/*")
public class MyServlet extends VaadinServlet {

}
@@ -0,0 +1,25 @@
/*
* Copyright 2000-2021 Vaadin Ltd.
*
* 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 limitations under
* the License.
*/

package com.vaadin.fusion.csrftest;

public class CsrfCookieWithTrailingSlashAndCustomContextIT
extends CsrfCookieWithTrailingSlashIT {
@Override
protected String getContextPath() {
return "/foo";
}
}
24 changes: 24 additions & 0 deletions flow-tests/test-fusion-csrf/frontend/index.html
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>fusion-csrf</title>
<style>
body {
margin: 0;
width: 100vw;
height: 100vh;
}

#outlet {
height: 100%;
}
</style>
<!-- index.ts is included here automatically (either by the dev server or during the build) -->
</head>

<body>
<div id="outlet"></div>
</body>
</html>
17 changes: 17 additions & 0 deletions flow-tests/test-fusion-csrf/frontend/index.ts
@@ -0,0 +1,17 @@
import { Router, Route } from '@vaadin/router';
import './views/helloworld/hello-world-view';

export const router = new Router(document.querySelector('#outlet'));

export const routes: Route[] = [
// place routes below (more info https://vaadin.com/docs/latest/fusion/routing/overview)
{
path: '',
component: 'hello-world-view',
},
{
path: 'hello',
component: 'hello-world-view',
}
];
router.setRoutes(routes);
@@ -0,0 +1,11 @@
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';

@customElement('hello-world-view')
export class HelloWorldView extends LitElement {
render() {
return html`
<div>HelloWorldView</div>
`;
}
}
133 changes: 133 additions & 0 deletions flow-tests/test-fusion-csrf/pom.xml
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.vaadin</groupId>
<artifactId>flow-tests</artifactId>
<version>9.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>test-fusion-csrf</artifactId>
<name>Fusion CSRF tests (dev mode)</name>
<description>
For https://github.com/vaadin/fusion/issues/105.
It verifies that the csrf cookie is added to correct path
when first open a sub view.
Note, the test needs to be in a separate module because
it needs to open a sub view first, put the test into another
module cannot gurantee this.
</description>
<version>9.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<!-- Project dependencies -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>fusion-endpoint</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dev-server</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
<execution>
<id>package-frontend-folder</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>frontend</classifier>
<classesDirectory>${project.basedir}/frontend</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- This module is mapped to default web context -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<systemProperties>
<systemProperty>
<!-- make sure we do not leave webpack-dev-server running after IT -->
<name>vaadin.reuseDevServer</name>
<value>false</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>flow-maven-plugin</artifactId>
<configuration>
<productionMode>false</productionMode>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>local-run</id>
<activation>
<property>
<name>!test.use.hub</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin
</artifactId>
<version>
${driver.binary.downloader.maven.plugin.version}
</version>
<configuration>
<onlyGetDriversForHostOperatingSystem>true
</onlyGetDriversForHostOperatingSystem>
<rootStandaloneServerDirectory>
${project.rootdir}/driver
</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>
${project.rootdir}/driver_zips
</downloadedZipFileDirectory>
<customRepositoryMap>
${project.rootdir}/drivers.xml
</customRepositoryMap>
</configuration>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

0 comments on commit 00226c1

Please sign in to comment.