x-fidelity 2.14.0 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.xfi-config.json +5 -0
- package/CHANGELOG.md +64 -0
- package/README.md +49 -2
- package/cli-testing/installBatsTesting.sh +9 -0
- package/cli-testing/test_cli_options.bats +86 -0
- package/dist/archetypes/java-microservice.json +1 -5
- package/dist/archetypes/node-fullstack-exemptions.json +1 -1
- package/dist/core/cli.js +1 -0
- package/dist/core/engine/analyzer.js +14 -8
- package/dist/core/engine/analyzer.test.js +44 -9
- package/dist/core/engine/engineRunner.js +14 -7
- package/dist/facts/repoDependencyFacts.js +101 -49
- package/dist/facts/repoDependencyFacts.test.js +47 -19
- package/dist/facts/repoFilesystemFacts.js +10 -1
- package/dist/operators/index.js +27 -4
- package/dist/rules/noDatabases-iterative-rule.json +2 -2
- package/dist/rules/sensitiveLogging-iterative-rule.json +10 -2
- package/dist/server/cacheManager.js +54 -32
- package/dist/server/middleware/validateTelemetryData.js +4 -2
- package/dist/server/middleware/validateUrlInput.js +11 -2
- package/dist/utils/configManager.js +42 -39
- package/dist/utils/exemptionLoader.js +3 -1
- package/dist/utils/inputValidation.js +23 -19
- package/dist/utils/inputValidation.test.js +19 -19
- package/dist/utils/jsonSchemas.js +20 -1
- package/dist/utils/openaiUtils.js +14 -1
- package/dist/utils/repoXFIConfigLoader.js +50 -0
- package/dist/utils/telemetry.js +2 -2
- package/dist/utils/utils.js +26 -0
- package/package.json +4 -2
- package/src/archetypes/java-microservice.json +1 -5
- package/src/archetypes/node-fullstack-exemptions.json +1 -1
- package/src/core/cli.ts +1 -0
- package/src/core/engine/analyzer.test.ts +44 -9
- package/src/core/engine/analyzer.ts +18 -11
- package/src/core/engine/engineRunner.ts +15 -8
- package/src/facts/openaiAnalysisFacts.test.ts +1 -1
- package/src/facts/openaiAnalysisFacts.ts +1 -1
- package/src/facts/repoDependencyFacts.test.ts +56 -16
- package/src/facts/repoDependencyFacts.ts +81 -33
- package/src/facts/repoFilesystemFacts.ts +14 -10
- package/src/index.ts +0 -1
- package/src/operators/index.ts +28 -7
- package/src/rules/noDatabases-iterative-rule.json +2 -2
- package/src/rules/sensitiveLogging-iterative-rule.json +10 -2
- package/src/server/cacheManager.ts +62 -33
- package/src/server/middleware/validateTelemetryData.ts +5 -3
- package/src/server/middleware/validateUrlInput.ts +14 -3
- package/src/types/typeDefs.ts +18 -1
- package/src/utils/configManager.ts +40 -40
- package/src/utils/exemptionLoader.ts +3 -1
- package/src/utils/inputValidation.test.ts +19 -19
- package/src/utils/inputValidation.ts +27 -25
- package/src/utils/jsonSchemas.ts +22 -2
- package/src/utils/openaiUtils.ts +14 -1
- package/src/utils/repoXFIConfigLoader.ts +36 -0
- package/src/utils/telemetry.ts +2 -2
- package/src/utils/utils.ts +25 -1
package/.xfi-config.json
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
# [2.16.0](https://github.com/zotoio/x-fidelity/compare/v2.15.0...v2.16.0) (2024-09-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Add null checks for child.stdout and child.stderr in collectYarnDependencies function ([cd3f271](https://github.com/zotoio/x-fidelity/commit/cd3f2714ed20dbed7f13c559110cc6721a237380))
|
|
7
|
+
* add type assertion to resolve TypeScript error ([aeb4c52](https://github.com/zotoio/x-fidelity/commit/aeb4c525c4a9e30a702ffcfb4b64f6a5a40a7bf3))
|
|
8
|
+
* cast util.promisify to unknown before mocking ([f8c5069](https://github.com/zotoio/x-fidelity/commit/f8c5069757fcbcbb3e391262812713dd1f3522f2))
|
|
9
|
+
* collect Yarn dependencies when yarn.lock exists ([48c50d1](https://github.com/zotoio/x-fidelity/commit/48c50d19d6d2ea422f41eab3b317e8e2071e11db))
|
|
10
|
+
* Collect Yarn dependencies when yarn.lock exists ([2e159f0](https://github.com/zotoio/x-fidelity/commit/2e159f0aa93aad2097c2038a940c1f814a990de6))
|
|
11
|
+
* Handle error types in dependency collection functions ([1711cb1](https://github.com/zotoio/x-fidelity/commit/1711cb153c07fcf8706e9a16431eda9ee4873f8e))
|
|
12
|
+
* increase Jest timeout for repoDependencyFacts.test.ts ([05185d9](https://github.com/zotoio/x-fidelity/commit/05185d9664bc5e69abd78772c8781308360b4b59))
|
|
13
|
+
* Mock child_process.exec to return a mock function ([ebba176](https://github.com/zotoio/x-fidelity/commit/ebba17659553f8f9e69fdc53b6cbdd1cab808412))
|
|
14
|
+
* **promisechain:** avoid skipped files ([0cdf825](https://github.com/zotoio/x-fidelity/commit/0cdf825a100900ac545795fb24099778af656653))
|
|
15
|
+
* Refactor runEngineOnFiles to use synchronous approach ([77c259e](https://github.com/zotoio/x-fidelity/commit/77c259ea3097b0fac50371acb2605285adc706c5))
|
|
16
|
+
* resolve TypeScript error in repoDependencyFacts.test.ts ([075e884](https://github.com/zotoio/x-fidelity/commit/075e884f32547c4b2f1beed730675449c57b26aa))
|
|
17
|
+
* resolve TypeScript error in repoDependencyFacts.test.ts ([6c4870e](https://github.com/zotoio/x-fidelity/commit/6c4870e766c18010566b474ff998d0eb084df364))
|
|
18
|
+
* Resolve TypeScript errors in repoDependencyFacts.test.ts ([bd47c66](https://github.com/zotoio/x-fidelity/commit/bd47c66c44443b0f485dd83fa345411fb16c85a1))
|
|
19
|
+
* update analyzer.test.ts to use expect.any(Number) for fileCount, totalIssues, and warningCount ([66bbd47](https://github.com/zotoio/x-fidelity/commit/66bbd47381694454a4016c5b6f610c4065c7c80e))
|
|
20
|
+
* update minimum dependency version comparison ([3373646](https://github.com/zotoio/x-fidelity/commit/3373646a9d2ff52a545dad44241191a952705ce2))
|
|
21
|
+
* Update mocking of util.promisify and fs.existsSync in repoDependencyFacts.test.ts ([fa81048](https://github.com/zotoio/x-fidelity/commit/fa81048ff7707c0def5a15d43ea34a36b202a725))
|
|
22
|
+
* Update mocking of util.promisify in repoDependencyFacts.test.ts ([8e6a18d](https://github.com/zotoio/x-fidelity/commit/8e6a18d0cb31c049bd0b923f88b655d891dbe712))
|
|
23
|
+
* Update repoDependencyFacts to fix test issues ([8d4bfc1](https://github.com/zotoio/x-fidelity/commit/8d4bfc1b9ef45ef64f9df33e2fe82ac0001d93bf))
|
|
24
|
+
* Update runEngineOnFiles function to handle asynchronous engine.run() call ([01ec5b0](https://github.com/zotoio/x-fidelity/commit/01ec5b0ed7a662c615000860374bc94c50e499bc))
|
|
25
|
+
* Update test expectations for `analyzeCodebase` ([524f0d3](https://github.com/zotoio/x-fidelity/commit/524f0d35e8d26a808189f5e5cbb6ce1b7c525244))
|
|
26
|
+
* Update test expectations for error handling in analyzer ([a986892](https://github.com/zotoio/x-fidelity/commit/a986892cf19303458fa2096dfeb58a705de3f242))
|
|
27
|
+
* Update test expectations for handling errors during analysis ([6a9c1b9](https://github.com/zotoio/x-fidelity/commit/6a9c1b9ac28696696c63d7e1a5c0a076856ac2d7))
|
|
28
|
+
* update unit tests for loading npm and yarn dependencies ([4faf703](https://github.com/zotoio/x-fidelity/commit/4faf703aac483f8a75d81f38545a371d91bb31d3))
|
|
29
|
+
* Use `exec` instead of `spawn` for collecting yarn dependencies ([b6bd17c](https://github.com/zotoio/x-fidelity/commit/b6bd17c74fee135b68a3d3fbb7ef6ee0750bf519))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* Replace execSync with spawned child process for dependency collection ([bd4b38e](https://github.com/zotoio/x-fidelity/commit/bd4b38e5f8dfb5b47c0fe2f07701ac38a16d78b2))
|
|
35
|
+
* Update analyzer.test.ts with more precise expectations ([7376191](https://github.com/zotoio/x-fidelity/commit/7376191ecc18f0ac1367ad13b68e52c085c832c5))
|
|
36
|
+
* update repoDependencyFacts tests to match implementation ([9514c3a](https://github.com/zotoio/x-fidelity/commit/9514c3a97e1c85bac7aa070c1efae8c0e5625073))
|
|
37
|
+
|
|
38
|
+
# [2.15.0](https://github.com/zotoio/x-fidelity/compare/v2.14.0...v2.15.0) (2024-09-08)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Bug Fixes
|
|
42
|
+
|
|
43
|
+
* **execution:** fact functions and cleanup ([8bd2cfa](https://github.com/zotoio/x-fidelity/commit/8bd2cfa8c4ea6a587fdf4259d34e14e09189fc27))
|
|
44
|
+
* Implement more robust error handling and logging ([f391052](https://github.com/zotoio/x-fidelity/commit/f391052b1b3fe8f56bb29deffaf567b2a32ce3d7))
|
|
45
|
+
* Implement safe handling of circular JSON references in repoDependencyFacts.ts ([49d95da](https://github.com/zotoio/x-fidelity/commit/49d95da03f4552de4533a0e86d37d4e168bd038e))
|
|
46
|
+
* **loading:** consistency with archetype ([47f52e4](https://github.com/zotoio/x-fidelity/commit/47f52e477c1e2ca69c49af767e9af5c8b76a7979))
|
|
47
|
+
* Update import statement in repoFilesystemFacts.ts ([903326c](https://github.com/zotoio/x-fidelity/commit/903326cb1dc33da38d5a9fcf7a45f01c4f1f4876))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Features
|
|
51
|
+
|
|
52
|
+
* Add JSON schema validation for .xfi-config.json file ([a7d0a75](https://github.com/zotoio/x-fidelity/commit/a7d0a755abe18ae07f8c1ef938b0eb2239af968b))
|
|
53
|
+
* Add rule to check for 'nuit' and 'elevate' package imports in the same file ([70d0994](https://github.com/zotoio/x-fidelity/commit/70d09947ff9149da22047a0d2f9dc62448de9fd0))
|
|
54
|
+
* Add support for .xfi-config.json file ([e9b60d3](https://github.com/zotoio/x-fidelity/commit/e9b60d31ac1037d6f40505deff5126f18409c269))
|
|
55
|
+
* Add support for .xfi-config.json file with sensitiveFileFalsePositives ([5eda4f4](https://github.com/zotoio/x-fidelity/commit/5eda4f4df4d5df048d6342e890825064e78b93e0))
|
|
56
|
+
* Add XFIConfig to ResultMetadata and define FileData and ValidationResult types ([ce71d90](https://github.com/zotoio/x-fidelity/commit/ce71d903c5211d1101bf49080a0fc3978b4cdaf2))
|
|
57
|
+
* Centralize loading of .xfi-config.json and add it as a fact ([2cca682](https://github.com/zotoio/x-fidelity/commit/2cca68203f2cd04d6802e25e3647455279d009a2))
|
|
58
|
+
* create 'bats' subdirectory and move BATS-related content ([1cc0bff](https://github.com/zotoio/x-fidelity/commit/1cc0bff7fec4d0d1b4c7ea60dd8fef027bc689f2))
|
|
59
|
+
* improve and modernize the bats test ([586b546](https://github.com/zotoio/x-fidelity/commit/586b546e50de46d5afe4e2dcde34af7fe65bbdb7))
|
|
60
|
+
* Improve repoDependencyAnalysis function ([a5638ca](https://github.com/zotoio/x-fidelity/commit/a5638cad789bc52533862dd91b9a964da785c666))
|
|
61
|
+
* Rename XFIConfig to RepoXFIConfig ([f91574d](https://github.com/zotoio/x-fidelity/commit/f91574d7c9ab4a1e64a9b2b8fb34fb84929a87bd))
|
|
62
|
+
* **repoconfig:** support for local control of false positive sensitive values ([db0b09a](https://github.com/zotoio/x-fidelity/commit/db0b09ae08dea2cc82a26a6a671615033805396b))
|
|
63
|
+
* **testing:** cli blackbox testing ([a634258](https://github.com/zotoio/x-fidelity/commit/a6342584a4a7cdfd630437fd9894a02039d0099d))
|
|
64
|
+
|
|
1
65
|
# [2.14.0](https://github.com/zotoio/x-fidelity/compare/v2.13.1...v2.14.0) (2024-08-29)
|
|
2
66
|
|
|
3
67
|
|
package/README.md
CHANGED
|
@@ -39,15 +39,25 @@ x-fidelity is an advanced CLI tool and paired config server designed to perform
|
|
|
39
39
|
3. [Components and entity names to understand](#components-and-entity-names-to-understand)
|
|
40
40
|
4. [System Architecture](#system-architecture)
|
|
41
41
|
5. [Configuring and Extending x-fidelity](#configuring-and-extending-x-fidelity)
|
|
42
|
+
- [Defining Archetypes](#defining-archetypes)
|
|
43
|
+
- [Defining rules](#defining-rules)
|
|
44
|
+
- [Included Operators](#included-operators)
|
|
42
45
|
6. [Installation](#installation)
|
|
43
46
|
7. [Usage](#usage)
|
|
47
|
+
- [Basic Usage](#basic-usage)
|
|
48
|
+
- [Advanced Usage](#advanced-usage)
|
|
49
|
+
- [Environment Variables](#environment-variables)
|
|
50
|
+
- [Local Configuration](#local-configuration)
|
|
51
|
+
- [Remote Configuration](#remote-configuration)
|
|
44
52
|
8. [Hosting Config Servers](#hosting-config-servers)
|
|
53
|
+
- [Docker Example](#docker-example)
|
|
45
54
|
9. [Exemptions](#exemptions)
|
|
46
55
|
10. [CI Pipeline Integration](#ci-pipeline-integration)
|
|
47
56
|
11. [OpenAI Integration](#openai-integration)
|
|
48
57
|
12. [X-Fi Best Practices](#x-fi-best-practices)
|
|
49
|
-
13. [
|
|
50
|
-
14. [
|
|
58
|
+
13. [Using .xfi-config.json](#using-xfi-configjson)
|
|
59
|
+
14. [Contributing](#contributing)
|
|
60
|
+
15. [License](#license)
|
|
51
61
|
|
|
52
62
|
## Intent and Purpose
|
|
53
63
|
|
|
@@ -758,6 +768,43 @@ This structure allows you to create custom AI-powered rules that can analyze you
|
|
|
758
768
|
7. **Performance**: Be mindful of the performance impact, especially for large codebases.
|
|
759
769
|
8. **Centralized Management**: Use a config server to manage and distribute your archetypes and rules across projects.
|
|
760
770
|
|
|
771
|
+
## Using .xfi-config.json
|
|
772
|
+
|
|
773
|
+
The `.xfi-config.json` file allows you to configure x-fidelity behavior specific to your repository. This file should be placed in the root of your project directory.
|
|
774
|
+
|
|
775
|
+
### Configuration Options
|
|
776
|
+
|
|
777
|
+
Currently, the `.xfi-config.json` file supports the following options:
|
|
778
|
+
|
|
779
|
+
1. `sensitiveFileFalsePositives`: An array of file paths that should be excluded from sensitive data checks.
|
|
780
|
+
|
|
781
|
+
Example `.xfi-config.json`:
|
|
782
|
+
|
|
783
|
+
```json
|
|
784
|
+
{
|
|
785
|
+
"sensitiveFileFalsePositives": [
|
|
786
|
+
"path/to/exclude/file1.js",
|
|
787
|
+
"path/to/exclude/file2.ts"
|
|
788
|
+
]
|
|
789
|
+
}
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
### How It Works
|
|
793
|
+
|
|
794
|
+
- When x-fidelity runs, it looks for the `.xfi-config.json` file in your project's root directory.
|
|
795
|
+
- If found, it applies the configurations specified in this file.
|
|
796
|
+
- For `sensitiveFileFalsePositives`, the specified files will be excluded from checks that look for sensitive data, such as API keys or passwords.
|
|
797
|
+
|
|
798
|
+
### How to use it
|
|
799
|
+
|
|
800
|
+
1. **Version Control**: Include `.xfi-config.json` in your version control system to ensure consistency across your team.
|
|
801
|
+
2. **Documentation**: Add comments in the listed file explaining why it is a false positive.
|
|
802
|
+
3. **Regular Review**: Periodically review your `.xfi-config.json` to ensure the exclusions are still necessary and valid.
|
|
803
|
+
4. **Minimal Use**: Use exclusions sparingly. It's better to fix issues than to exclude them from checks.
|
|
804
|
+
5. **Feedback**: If the rules being applied are resulting in too many false-postives, speak with the team that manages your central rule config.
|
|
805
|
+
|
|
806
|
+
Remember, while `.xfi-config.json` allows you to adjust x-fidelity's behavior in limited ways, it should be used judiciously to maintain the integrity of your code quality checks.
|
|
807
|
+
|
|
761
808
|
## Contributing
|
|
762
809
|
|
|
763
810
|
Contributions to x-fidelity are welcome! Please refer to the `CONTRIBUTING.md` file for guidelines on how to contribute to this project.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
yarn global add bats
|
|
4
|
+
|
|
5
|
+
git clone https://github.com/bats-core/bats-support.git test_helper/bats-support
|
|
6
|
+
git clone https://github.com/bats-core/bats-assert.git test_helper/bats-assert
|
|
7
|
+
|
|
8
|
+
echo "bats cli testing framework installed. you can now run 'yarn bats:test'"
|
|
9
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env bats
|
|
2
|
+
|
|
3
|
+
setup() {
|
|
4
|
+
load './test_helper/bats-support/load'
|
|
5
|
+
load './test_helper/bats-assert/load'
|
|
6
|
+
ln -s ../dist/index.js ./xfidelity
|
|
7
|
+
chmod 755 ./xfidelity
|
|
8
|
+
BATS_TEST_TIMEOUT=10
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
teardown() {
|
|
12
|
+
./xfidelity 3>&-
|
|
13
|
+
rm ./xfidelity
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@test "CLI displays help information with -h option" {
|
|
17
|
+
run ./xfidelity --help
|
|
18
|
+
assert_success
|
|
19
|
+
assert_output --partial "Usage:"
|
|
20
|
+
assert_output --partial "--dir <directory>"
|
|
21
|
+
assert_output --partial "--archetype <archetype>"
|
|
22
|
+
assert_output --partial "--configServer <configServer>"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@test "CLI displays version number with -v option" {
|
|
26
|
+
run ./xfidelity --version
|
|
27
|
+
assert_success
|
|
28
|
+
assert_output --regexp '^[0-9]+\.[0-9]+\.[0-9]$'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@test "CLI analyzes specified directory" {
|
|
32
|
+
run ./xfidelity --dir "/home/andrewv/git/x-fidelity/src"
|
|
33
|
+
assert_success
|
|
34
|
+
assert_output --partial "directory: /home/andrewv/git/x-fidelity/src"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@test "CLI uses the specified archetype for analysis" {
|
|
38
|
+
run ./xfidelity --archetype "java-microservice" --dir "/home/andrewv/git/x-fidelity/src"
|
|
39
|
+
assert_success
|
|
40
|
+
assert_output --partial "archetype: java-microservice"
|
|
41
|
+
assert_output --partial "directory: /home/andrewv/git/x-fidelity/src"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@test "CLI runs server on specified port" {
|
|
45
|
+
./xfidelity --mode server --port 9079 &
|
|
46
|
+
pid=$!
|
|
47
|
+
|
|
48
|
+
while ! nc -vz localhost 9079 > /dev/null 2>&1 ; do
|
|
49
|
+
# echo sleeping
|
|
50
|
+
sleep 0.1
|
|
51
|
+
done
|
|
52
|
+
|
|
53
|
+
curl localhost:9079 || kill "$pid"
|
|
54
|
+
|
|
55
|
+
# Kill Pid
|
|
56
|
+
kill $pid
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@test "CLI enables OpenAI analysis" {
|
|
60
|
+
OPENAI_API_KEY=abc
|
|
61
|
+
run ./xfidelity --openaiEnabled true --dir "../src"
|
|
62
|
+
assert_success
|
|
63
|
+
assert_output --partial "openaiEnabled: true"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@test "CLI uses specified config server URL" {
|
|
67
|
+
run ./xfidelity --configServer "http://127.0.0.1/config" --dir "../src"
|
|
68
|
+
assert_success
|
|
69
|
+
assert_output --partial "configServer: http://127.0.0.1/config"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@test "CLI sets JSON TTL" {
|
|
73
|
+
run ./xfidelity --jsonTTL 30 --dir "../src"
|
|
74
|
+
assert_success
|
|
75
|
+
assert_output --partial "jsonTTL: 30"
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@test "CLI handles multiple options correctly" {
|
|
79
|
+
run ./xfidelity --dir "/home/andrewv/git/x-fidelity/src" --archetype "node-fullstack" --jsonTTL 45
|
|
80
|
+
assert_success
|
|
81
|
+
assert_output --partial "directory: /home/andrewv/git/x-fidelity/src"
|
|
82
|
+
assert_output --partial "archetype: node-fullstack"
|
|
83
|
+
assert_output --partial "openaiEnabled: false"
|
|
84
|
+
assert_output --partial "jsonTTL: 45"
|
|
85
|
+
assert_output --partial "mode: client"
|
|
86
|
+
}
|
|
@@ -2,18 +2,14 @@
|
|
|
2
2
|
"name": "java-microservice",
|
|
3
3
|
"rules": [
|
|
4
4
|
"sensitiveLogging-iterative",
|
|
5
|
-
"outdatedFramework-global",
|
|
6
|
-
"noDatabases-iterative",
|
|
7
5
|
"nonStandardDirectoryStructure-global"
|
|
8
6
|
],
|
|
9
7
|
"operators": [
|
|
10
8
|
"fileContains",
|
|
11
|
-
"outdatedFramework",
|
|
12
9
|
"nonStandardDirectoryStructure"
|
|
13
10
|
],
|
|
14
11
|
"facts": [
|
|
15
|
-
"repoFilesystemFacts"
|
|
16
|
-
"repoDependencyFacts"
|
|
12
|
+
"repoFilesystemFacts"
|
|
17
13
|
],
|
|
18
14
|
"config": {
|
|
19
15
|
"minimumDependencyVersions": {
|
package/dist/core/cli.js
CHANGED
|
@@ -92,6 +92,7 @@ mode: ${options.mode}
|
|
|
92
92
|
port: ${options.mode === 'server' ? options.port : 'n/a'}
|
|
93
93
|
localConfigPath: ${options.localConfigPath ? options.localConfigPath : 'none'}
|
|
94
94
|
jsonTTL: ${options.jsonTTL} minutes
|
|
95
|
+
openaiEnabled: ${options.openaiEnabled}
|
|
95
96
|
for options run: xfidelity --help
|
|
96
97
|
=====================================`);
|
|
97
98
|
logger_1.logger.info(banner);
|
|
@@ -15,6 +15,7 @@ const configManager_1 = require("../../utils/configManager");
|
|
|
15
15
|
const openaiUtils_1 = require("../../utils/openaiUtils");
|
|
16
16
|
const telemetry_1 = require("../../utils/telemetry");
|
|
17
17
|
const repoFilesystemFacts_1 = require("../../facts/repoFilesystemFacts");
|
|
18
|
+
const repoXFIConfigLoader_1 = require("../../utils/repoXFIConfigLoader");
|
|
18
19
|
const repoDependencyFacts_1 = require("../../facts/repoDependencyFacts");
|
|
19
20
|
const openaiAnalysisFacts_1 = require("../../facts/openaiAnalysisFacts");
|
|
20
21
|
const telemetryCollector_1 = require("./telemetryCollector");
|
|
@@ -43,6 +44,7 @@ function analyzeCodebase(params) {
|
|
|
43
44
|
}, executionLogPrefix);
|
|
44
45
|
const installedDependencyVersions = yield (0, repoDependencyFacts_1.getDependencyVersionFacts)(archetypeConfig);
|
|
45
46
|
const fileData = yield (0, repoFilesystemFacts_1.collectRepoFileData)(repoPath, archetypeConfig);
|
|
47
|
+
const repoXFIConfig = yield (0, repoXFIConfigLoader_1.loadRepoXFIConfig)(repoPath);
|
|
46
48
|
// add REPO_GLOBAL_CHECK to fileData, which is the trigger for global checks
|
|
47
49
|
fileData.push({
|
|
48
50
|
fileName: configManager_1.REPO_GLOBAL_CHECK,
|
|
@@ -66,9 +68,12 @@ function analyzeCodebase(params) {
|
|
|
66
68
|
engine.addFact('openaiAnalysis', openaiAnalysisFacts_1.openaiAnalysis);
|
|
67
69
|
engine.addFact('openaiSystemPrompt', openaiSystemPrompt);
|
|
68
70
|
}
|
|
69
|
-
// add
|
|
71
|
+
// add functions for dependency and file analysis
|
|
70
72
|
engine.addFact('repoDependencyAnalysis', repoDependencyFacts_1.repoDependencyAnalysis);
|
|
71
73
|
engine.addFact('repoFileAnalysis', repoFilesystemFacts_1.repoFileAnalysis);
|
|
74
|
+
// add xfiConfig as a fact
|
|
75
|
+
engine.addFact('repoXFIConfig', repoXFIConfig);
|
|
76
|
+
logger_1.logger.info(`Added repoXFIConfig as fact: ${(0, utils_1.safeStringify)(repoXFIConfig)}`);
|
|
72
77
|
const failures = yield (0, engineRunner_1.runEngineOnFiles)({
|
|
73
78
|
engine,
|
|
74
79
|
fileData,
|
|
@@ -88,18 +93,19 @@ function analyzeCodebase(params) {
|
|
|
88
93
|
const resultMetadata = {
|
|
89
94
|
XFI_RESULT: {
|
|
90
95
|
archetype,
|
|
91
|
-
|
|
96
|
+
telemetryData,
|
|
97
|
+
repoXFIConfig: repoXFIConfig,
|
|
98
|
+
issueDetails: failures,
|
|
99
|
+
startTime: telemetryData.startTime,
|
|
100
|
+
finishTime: finishTime,
|
|
101
|
+
durationSeconds: (finishTime - telemetryData.startTime) / 1000,
|
|
92
102
|
fileCount: fileData.length,
|
|
93
103
|
totalIssues: totalFailureCount,
|
|
94
104
|
warningCount: warningCount,
|
|
95
105
|
fatalityCount: fatalityCount,
|
|
96
106
|
exemptCount: exemptCount,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
finishTime: finishTime,
|
|
100
|
-
durationSeconds: (finishTime - telemetryData.startTime) / 1000,
|
|
101
|
-
telemetryData,
|
|
102
|
-
options: cli_1.options
|
|
107
|
+
options: cli_1.options,
|
|
108
|
+
repoPath,
|
|
103
109
|
}
|
|
104
110
|
};
|
|
105
111
|
// Send telemetry for analysis end
|
|
@@ -122,15 +122,34 @@ describe('analyzeCodebase', () => {
|
|
|
122
122
|
archetype: 'node-fullstack',
|
|
123
123
|
repoPath: 'mockRepoPath',
|
|
124
124
|
fileCount: 3,
|
|
125
|
-
totalIssues:
|
|
126
|
-
warningCount:
|
|
127
|
-
fatalityCount:
|
|
128
|
-
|
|
125
|
+
totalIssues: expect.any(Number),
|
|
126
|
+
warningCount: expect.any(Number),
|
|
127
|
+
fatalityCount: expect.any(Number),
|
|
128
|
+
exemptCount: expect.any(Number),
|
|
129
|
+
issueDetails: expect.any(Array),
|
|
129
130
|
durationSeconds: expect.any(Number),
|
|
130
131
|
finishTime: expect.any(Number),
|
|
131
132
|
startTime: expect.any(Number),
|
|
132
|
-
options: expect.
|
|
133
|
-
|
|
133
|
+
options: expect.objectContaining({
|
|
134
|
+
archetype: 'node-fullstack',
|
|
135
|
+
configServer: '',
|
|
136
|
+
dir: 'mockDir',
|
|
137
|
+
localConfigPath: '',
|
|
138
|
+
mode: 'cli',
|
|
139
|
+
openaiEnabled: true,
|
|
140
|
+
port: '8888',
|
|
141
|
+
telemetryCollector: '',
|
|
142
|
+
}),
|
|
143
|
+
telemetryData: expect.objectContaining({
|
|
144
|
+
configServer: 'none',
|
|
145
|
+
hostInfo: expect.any(Object),
|
|
146
|
+
repoUrl: '',
|
|
147
|
+
startTime: expect.any(Number),
|
|
148
|
+
userInfo: expect.any(Object),
|
|
149
|
+
}),
|
|
150
|
+
repoXFIConfig: expect.objectContaining({
|
|
151
|
+
sensitiveFileFalsePositives: expect.any(Array),
|
|
152
|
+
})
|
|
134
153
|
})
|
|
135
154
|
});
|
|
136
155
|
expect(telemetry_1.sendTelemetry).toHaveBeenCalledTimes(2); // Once for start, once for end
|
|
@@ -174,15 +193,32 @@ describe('analyzeCodebase', () => {
|
|
|
174
193
|
archetype: 'node-fullstack',
|
|
175
194
|
repoPath: 'mockRepoPath',
|
|
176
195
|
fileCount: 3,
|
|
177
|
-
totalIssues:
|
|
196
|
+
totalIssues: 3,
|
|
178
197
|
warningCount: 0,
|
|
179
198
|
fatalityCount: 0,
|
|
180
|
-
|
|
199
|
+
exemptCount: 0,
|
|
200
|
+
issueDetails: expect.arrayContaining([
|
|
201
|
+
expect.objectContaining({
|
|
202
|
+
filePath: expect.any(String),
|
|
203
|
+
errors: expect.arrayContaining([
|
|
204
|
+
expect.objectContaining({
|
|
205
|
+
ruleFailure: 'ProcessingError',
|
|
206
|
+
level: 'error',
|
|
207
|
+
details: expect.objectContaining({
|
|
208
|
+
message: expect.stringContaining('Error processing file: Error: mock error')
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
])
|
|
212
|
+
})
|
|
213
|
+
]),
|
|
181
214
|
durationSeconds: expect.any(Number),
|
|
182
215
|
finishTime: expect.any(Number),
|
|
183
216
|
startTime: expect.any(Number),
|
|
184
217
|
options: expect.any(Object),
|
|
185
218
|
telemetryData: expect.any(Object),
|
|
219
|
+
repoXFIConfig: expect.objectContaining({
|
|
220
|
+
sensitiveFileFalsePositives: expect.any(Array)
|
|
221
|
+
})
|
|
186
222
|
})
|
|
187
223
|
});
|
|
188
224
|
expect(telemetry_1.sendTelemetry).toHaveBeenCalledTimes(2); // Once for start, once for end
|
|
@@ -216,7 +252,6 @@ describe('analyzeCodebase', () => {
|
|
|
216
252
|
repoPath: 'mockRepoPath',
|
|
217
253
|
archetype: 'node-fullstack'
|
|
218
254
|
});
|
|
219
|
-
expect(engineAddFactMock).toHaveBeenCalledWith('repoDependencyAnalysis', expect.any(Function));
|
|
220
255
|
expect(telemetry_1.sendTelemetry).toHaveBeenCalledTimes(2); // Once for start, once for end
|
|
221
256
|
}));
|
|
222
257
|
it('should not add OpenAI facts when OpenAI is not enabled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -14,11 +14,12 @@ const logger_1 = require("../../utils/logger");
|
|
|
14
14
|
const configManager_1 = require("../../utils/configManager");
|
|
15
15
|
function runEngineOnFiles(params) {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
var _a, _b;
|
|
17
18
|
const { engine, fileData, installedDependencyVersions, minimumDependencyVersions, standardStructure } = params;
|
|
18
19
|
const msg = `\n==========================\nRUNNING FILE CHECKS..\n==========================`;
|
|
19
20
|
logger_1.logger.info(msg);
|
|
20
21
|
const failures = [];
|
|
21
|
-
const
|
|
22
|
+
for (const file of fileData) {
|
|
22
23
|
if (file.fileName === configManager_1.REPO_GLOBAL_CHECK) {
|
|
23
24
|
const msg = `\n==========================\nRUNNING GLOBAL REPO CHECKS..\n==========================`;
|
|
24
25
|
logger_1.logger.info(msg);
|
|
@@ -38,8 +39,7 @@ function runEngineOnFiles(params) {
|
|
|
38
39
|
const fileFailures = [];
|
|
39
40
|
try {
|
|
40
41
|
const { results } = yield engine.run(facts);
|
|
41
|
-
|
|
42
|
-
var _a, _b;
|
|
42
|
+
for (const result of results) {
|
|
43
43
|
logger_1.logger.debug(JSON.stringify(result));
|
|
44
44
|
if (result.result) {
|
|
45
45
|
fileFailures.push({
|
|
@@ -48,16 +48,23 @@ function runEngineOnFiles(params) {
|
|
|
48
48
|
details: (_b = result.event) === null || _b === void 0 ? void 0 : _b.params
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
if (fileFailures.length > 0) {
|
|
53
53
|
failures.push({ filePath: file.filePath, errors: fileFailures });
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
catch (e) {
|
|
57
|
-
logger_1.logger.error(e);
|
|
57
|
+
logger_1.logger.error(`Error processing file ${file.filePath}: ${e}`);
|
|
58
|
+
failures.push({
|
|
59
|
+
filePath: file.filePath,
|
|
60
|
+
errors: [{
|
|
61
|
+
ruleFailure: 'ProcessingError',
|
|
62
|
+
level: 'error',
|
|
63
|
+
details: { message: `Error processing file: ${e}` }
|
|
64
|
+
}]
|
|
65
|
+
});
|
|
58
66
|
}
|
|
59
|
-
}
|
|
60
|
-
yield Promise.all(enginePromises);
|
|
67
|
+
}
|
|
61
68
|
return failures;
|
|
62
69
|
});
|
|
63
70
|
}
|