From 31f88fddb791b4208e9c08e709041fa7dcb6f1e6 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 24 Jul 2018 08:05:48 +0200 Subject: [PATCH 1/7] execute test with coverage durring build --- scm-ui/pom.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scm-ui/pom.xml b/scm-ui/pom.xml index b7595d3d76..496d151fb7 100644 --- a/scm-ui/pom.xml +++ b/scm-ui/pom.xml @@ -29,7 +29,7 @@ YARN - 1.3.2 + 1.7.0 @@ -51,6 +51,16 @@ + + test + test + + run + + + + + From cb6b0d0ee67bcb0af3a2810b2cff667f614c1d95 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 24 Jul 2018 08:45:37 +0200 Subject: [PATCH 2/7] added sonarqube properties to scm-ui module --- scm-ui/package.json | 12 ++++++++++++ scm-ui/pom.xml | 12 ++++++++++-- scm-ui/yarn.lock | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/scm-ui/package.json b/scm-ui/package.json index de30ec8047..90c4460361 100644 --- a/scm-ui/package.json +++ b/scm-ui/package.json @@ -28,6 +28,7 @@ "build": "npm-run-all build-css build-js", "test": "jest", "test-coverage": "yarn run test --coverage", + "test-ci": "yarn run test --ci --coverage", "eject": "react-scripts eject", "flow": "flow" }, @@ -42,6 +43,7 @@ "fetch-mock": "^6.5.0", "flow-bin": "^0.75.0", "flow-typed": "^2.5.1", + "jest-junit": "^5.1.0", "node-sass-chokidar": "^1.3.0", "npm-run-all": "^4.1.3", "prettier": "^1.13.7", @@ -52,5 +54,15 @@ "presets": [ "react-app" ] + }, + "jest": { + "coverageDirectory": "target/coverage", + "coveragePathIgnorePatterns": [ + "src/tests/.*" + ], + "reporters": [ "default", "jest-junit" ] + }, + "jest-junit": { + "output": "./target/reports/jest-junit.xml" } } diff --git a/scm-ui/pom.xml b/scm-ui/pom.xml index 496d151fb7..a0b9518ccb 100644 --- a/scm-ui/pom.xml +++ b/scm-ui/pom.xml @@ -16,6 +16,15 @@ 2.0.0-SNAPSHOT scm-ui + + js + src + **/*.test.js,src/tests/** + **/*.test.js,src/tests/** + target/reports + target/coverage/lcov.info + + @@ -58,13 +67,12 @@ run - + - diff --git a/scm-ui/yarn.lock b/scm-ui/yarn.lock index fe4f475a0f..4063d5135d 100644 --- a/scm-ui/yarn.lock +++ b/scm-ui/yarn.lock @@ -4368,6 +4368,10 @@ jest-environment-node@^20.0.3: jest-mock "^20.0.3" jest-util "^20.0.3" +jest-get-type@^22.1.0: + version "22.4.3" + resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4" + jest-haste-map@^20.0.4: version "20.0.5" resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-20.0.5.tgz#abad74efb1a005974a7b6517e11010709cab9112" @@ -4393,6 +4397,15 @@ jest-jasmine2@^20.0.4: once "^1.4.0" p-map "^1.1.1" +jest-junit@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-5.1.0.tgz#e8e497d810a829bf02783125aab74b5df6caa8fe" + dependencies: + jest-validate "^23.0.1" + mkdirp "^0.5.1" + strip-ansi "^4.0.0" + xml "^1.0.1" + jest-matcher-utils@^20.0.3: version "20.0.3" resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-20.0.3.tgz#b3a6b8e37ca577803b0832a98b164f44b7815612" @@ -4491,6 +4504,15 @@ jest-validate@^20.0.3: leven "^2.1.0" pretty-format "^20.0.3" +jest-validate@^23.0.1: + version "23.4.0" + resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-23.4.0.tgz#d96eede01ef03ac909c009e9c8e455197d48c201" + dependencies: + chalk "^2.0.1" + jest-get-type "^22.1.0" + leven "^2.1.0" + pretty-format "^23.2.0" + jest@20.0.4: version "20.0.4" resolved "https://registry.yarnpkg.com/jest/-/jest-20.0.4.tgz#3dd260c2989d6dad678b1e9cc4d91944f6d602ac" @@ -6218,6 +6240,13 @@ pretty-format@^20.0.3: ansi-regex "^2.1.1" ansi-styles "^3.0.0" +pretty-format@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.2.0.tgz#3b0aaa63c018a53583373c1cb3a5d96cc5e83017" + dependencies: + ansi-regex "^3.0.0" + ansi-styles "^3.2.0" + private@^0.1.6, private@^0.1.7, private@^0.1.8: version "0.1.8" resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" @@ -8242,6 +8271,10 @@ xml-name-validator@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-2.0.1.tgz#4d8b8f1eccd3419aa362061becef515e1e559635" +xml@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5" + xtend@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" From bcc23074f6689091356aeee66c7786c7a31129ac Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 24 Jul 2018 08:50:38 +0200 Subject: [PATCH 3/7] change report path to match jenkinsfile test result location --- scm-ui/package.json | 4 ++-- scm-ui/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scm-ui/package.json b/scm-ui/package.json index 90c4460361..7c4148d825 100644 --- a/scm-ui/package.json +++ b/scm-ui/package.json @@ -56,13 +56,13 @@ ] }, "jest": { - "coverageDirectory": "target/coverage", + "coverageDirectory": "target/jest-reports/coverage", "coveragePathIgnorePatterns": [ "src/tests/.*" ], "reporters": [ "default", "jest-junit" ] }, "jest-junit": { - "output": "./target/reports/jest-junit.xml" + "output": "./target/jest-reports/TEST-all.xml" } } diff --git a/scm-ui/pom.xml b/scm-ui/pom.xml index a0b9518ccb..58c935ad21 100644 --- a/scm-ui/pom.xml +++ b/scm-ui/pom.xml @@ -21,8 +21,8 @@ src **/*.test.js,src/tests/** **/*.test.js,src/tests/** - target/reports - target/coverage/lcov.info + target/jest-reports + target/jest-reports/coverage/lcov.info From f5772893416949ac73345fa0258fe1570592b808 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 24 Jul 2018 08:53:40 +0200 Subject: [PATCH 4/7] fix build, by calling jest without yarn --- scm-ui/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scm-ui/package.json b/scm-ui/package.json index 7c4148d825..d5a642099f 100644 --- a/scm-ui/package.json +++ b/scm-ui/package.json @@ -27,8 +27,8 @@ "build-js": "react-scripts build", "build": "npm-run-all build-css build-js", "test": "jest", - "test-coverage": "yarn run test --coverage", - "test-ci": "yarn run test --ci --coverage", + "test-coverage": "jest --coverage", + "test-ci": "jest --ci --coverage", "eject": "react-scripts eject", "flow": "flow" }, From 947b9497d7e8fcd82558d8fa3b7fb2a9e1f2d1a8 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 24 Jul 2018 10:51:24 +0200 Subject: [PATCH 5/7] set build to unstable if a unit test fails --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4d11767e67..21e03f6d0a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,7 +31,7 @@ node() { // No specific label } stage('Unit Test') { - mvn 'test -Dsonia.scm.test.skip.hg=true' + mvn 'test -Dsonia.scm.test.skip.hg=true -Dmaven.test.failure.ignore=true' } stage('SonarQube') { From 1f60d76f7c04cbcbc2ee955b4be233910f8736f2 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 24 Jul 2018 12:56:58 +0200 Subject: [PATCH 6/7] fixed failing unit test --- .../java/sonia/scm/filter/SecurityFilter.java | 5 ---- .../sonia/scm/filter/SecurityFilterTest.java | 25 +++++++++++++++---- scm.iml | 5 ++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/filter/SecurityFilter.java b/scm-webapp/src/main/java/sonia/scm/filter/SecurityFilter.java index 965e097f64..01967afd00 100644 --- a/scm-webapp/src/main/java/sonia/scm/filter/SecurityFilter.java +++ b/scm-webapp/src/main/java/sonia/scm/filter/SecurityFilter.java @@ -70,11 +70,6 @@ public class SecurityFilter extends HttpFilter @VisibleForTesting static final String ATTRIBUTE_REMOTE_USER = "principal"; - /** Field description */ - public static final String URL_AUTHENTICATION = "/api/rest/auth"; - - public static final String URLV2_AUTHENTICATION = "/api/rest/v2/auth"; - private final ScmConfiguration configuration; @Inject diff --git a/scm-webapp/src/test/java/sonia/scm/filter/SecurityFilterTest.java b/scm-webapp/src/test/java/sonia/scm/filter/SecurityFilterTest.java index 13333cc223..983f8d964a 100644 --- a/scm-webapp/src/test/java/sonia/scm/filter/SecurityFilterTest.java +++ b/scm-webapp/src/test/java/sonia/scm/filter/SecurityFilterTest.java @@ -100,14 +100,29 @@ public class SecurityFilterTest { } /** - * Tests filter on authentication endpoint. - * + * Tests filter on authentication endpoint v1. + * * @throws IOException * @throws ServletException */ @Test - public void testDoOnAuthenticationUrl() throws IOException, ServletException { - when(request.getRequestURI()).thenReturn("/scm/api/rest/authentication"); + public void testDoOnAuthenticationUrlV1() throws IOException, ServletException { + checkIfAuthenticationUrlIsPassedThrough("/scm/api/rest/auth/access_token"); + } + + /** + * Tests filter on authentication endpoint v2. + * + * @throws IOException + * @throws ServletException + */ + @Test + public void testDoOnAuthenticationUrlV2() throws IOException, ServletException { + checkIfAuthenticationUrlIsPassedThrough("/scm/api/rest/v2/auth/access_token"); + } + + private void checkIfAuthenticationUrlIsPassedThrough(String uri) throws IOException, ServletException { + when(request.getRequestURI()).thenReturn(uri); securityFilter.doFilter(request, response, chain); verify(request, never()).setAttribute(Mockito.anyString(), Mockito.any()); verify(chain).doFilter(request, response); @@ -235,4 +250,4 @@ public class SecurityFilterTest { } -} \ No newline at end of file +} diff --git a/scm.iml b/scm.iml index a0d516ed9a..4ed0077c7f 100644 --- a/scm.iml +++ b/scm.iml @@ -12,5 +12,10 @@ + + + + + \ No newline at end of file From ef65b9265ae0ef2b8c023e9e8677f6643852fa53 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 24 Jul 2018 13:05:18 +0200 Subject: [PATCH 7/7] close branch feature/sonar-ui