Skip to content

Commit 4123861

Browse files
ribafishjacopoc
authored andcommitted
Fixed: remove generateSecretKeys dependency from test to improve build caching
The `test` task depends on `generateSecretKeys`, which writes new random values to `framework/security/config/security.properties` on every build. Since this file is part of the main resource source set (`config/` dirs are included via `getDirectoryInActiveComponentsIfExists('config')`), changing it causes cascading Gradle build cache misses for: - `:compileTestGroovy` — classpath includes main resources - `:checkstyleMain` — classpath includes `sourceSets.main.output` - `:checkstyleTest` — same reason - `:test` — classpath + test classes differ This commit: 1. Removes `dependsOn 'generateSecretKeys'` from the `test` task — the main `security.properties` is no longer mutated during `build` 2. Adds a test-specific `security.properties` in `framework/security/src/test/resources/` with fixed keys — this shadows the main config on the test classpath so unit tests that require JWT keys (e.g. `ModelFormTest`) continue to work The `generateSecretKeys` task is unchanged and remains available for manual use (`./gradlew generateSecretKeys`) and as a dependency of `loadAll`. (cherry picked from commit 73d0d37) (cherry picked from commit 4b59bc7)
1 parent 539dfa8 commit 4123861

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,10 @@ eclipse.classpath.file.whenMerged { classpath ->
309309
tasks.eclipse.dependsOn(cleanEclipse)
310310

311311
test {
312-
dependsOn 'generateSecretKeys'
313312
useJUnit()
314313
jvmArgs "-javaagent:${classpath.find { it.name.contains('jmockit') }.absolutePath}"
315314
}
316315

317-
processResources.mustRunAfter 'generateSecretKeys'
318316

319317
/* ========================================================
320318
* Tasks
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
##############################################################################
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
###############################################################################
19+
20+
##############################################################################
21+
# Test override of security.properties with non production values.
22+
# This file shadows framework/security/config/security.properties on the
23+
# test classpath so that unit tests requiring security settings such as
24+
# JWT keys can run without the need to generate keys or modify the main
25+
# security.properties file.
26+
##############################################################################
27+
28+
# -- Security key used to encrypt and decrypt the autogenerated password in forgot password functionality.
29+
# Read Passwords and JWT (JSON Web Tokens) usage documentation to choose the way you want to store this key
30+
# The key must be 512 bits (ie 64 chars) as we use HMAC512 to create the token, cf. OFBIZ-12724
31+
# Run './gradlew generateSecretKeys' to generate a cryptographically secure random key.
32+
login.secret_key_string=ZdxxqjX87e6CR9Rf5pAzA+GTX4DP2T0H3bimGaDGA59OytU/tVQ7AC7N9PUA9e17
33+
34+
# -- The secret key for the JWT token signature.
35+
# Read Passwords and JWT (JSON Web Tokens) usage documentation to choose the way you want to store this key
36+
# The key must be 512 bits (ie 64 chars) as we use HMAC512 to create the token, cf. OFBIZ-12724
37+
# Run './gradlew generateSecretKeys' to generate a cryptographically secure random key.
38+
security.token.key=TzWl/rNavz7VYMc6sxDpf8Yon6NnkbUfrL4JrscJBdTEx3vtwQQ7Mt0wk/TtZXUn
39+
40+
#-- To accept the execution on some groovy script who match the deniedScriptletsTokens regExp, put their hash here.
41+
#-- like allowedScriptletHashes={SHA}59f8ab616b3878ddf825ea50c13ce603a3a6c5a9,{SHA}59f5ab516b3878ddf825ea50c13ce603a3a6c5a9
42+
allowedScriptletHashes= {SHA}4e025676cfa6df142e3457099271ecdcd1c1f5f9,{SHA}d8451d7509ae73421974f47752b6e9eef7503041,{SHA}edf12cf95597d52eacc14020a85a8df2abb34ab7
43+
44+
#-- RegExp to secure groovy script execution. If the regExp match a script, it would be disabled and OFBiz run nothing.
45+
#-- In this case, you will have on log the original script with it hash. The hash can be added on allowedScriptletHashes
46+
#-- properties to accept it on the next execution.
47+
deniedScriptletsTokens=java\\s*\.|import\\s|embed[^\\w]|process[^\\w]|class[^\\w]|require[^\\w]\
48+
|\.\\s*.exec.*[\(|\\s]|\.\\s*calc.*[\(|\\s]|\.\\s*.eval.*[\(|\\s]|Eval\\s*\.|\\s+File\
49+
|System\\s*\.|\.\\s*codehaus|\.\\s*groovy[^:]|\.\\s*runtime\|groovyx\\s*\.
50+
51+
#-- If you want to deactivate the security control on each groovy script set to false.
52+
# Warn ensure to be sure on what you do because this can open the door for code injection
53+
useDeniedScriptletsTokens=true

0 commit comments

Comments
 (0)