Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to v0.2.0 #18

Merged
merged 3 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Docker Image CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:

runs-on: ubuntu-latest

steps:
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
-
name: Docker Setup Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and Push Image
uses: docker/build-push-action@v5
with:
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/dotfiles:latest
cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/ptt:latest
cache-to: type=inline
2 changes: 2 additions & 0 deletions docs/SECURITY/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Security Documentation for Password Transformation Tool (PTT)
- No additional notes.
26 changes: 26 additions & 0 deletions docs/SECURITY/semgrep-scan.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


┌────────────────┐
│ 1 Code Finding │
└────────────────┘

 main.go
❯❱ trailofbits.go.iterate-over-empty-map.iterate-over-empty-map
Iteration over a possibly empty map `modes`. This is likely a bug or redundant code
Details: https://sg.run/08jj

41┆ modes := map[string]string{
42┆ "append": "Transforms input into append rules.",
43┆ "append-remove": "Transforms input into append-remove rules.",
44┆ "append-shift": "Transforms input into append-shift rules.",
45┆ "prepend": "Transforms input into prepend rules.",
46┆ "prepend-remove": "Transforms input into prepend-remove rules.",
47┆ "prepend-shift": "Transforms input into prepend-shift rules.",
48┆ "insert -i [index]": "Transforms input into insert rules starting at
index.",
49┆ "overwrite -i [index]": "Transforms input into overwrite rules starting at
index.",
50┆ "toggle -i [index]": "Transforms input into toggle rules starting at
index.",
[hid 18 additional lines, adjust with --max-lines-per-finding]

10 changes: 6 additions & 4 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ There are some additional notes when importing data:
- When reading from standard input, the tool can detect chaining `ptt` commands
when the `-v` flag is used. This can be used to pipe multiple commands together.
- When reading from files, the tool can detect when `ptt` JSON output is used as input and will parse the JSON data.
- The `-b` flag can be used to bypass map creation and use stdout as primary output. This can be useful for working with large amounts of data.
- If the `-b` flag is used, the final output will be empty and all
filtering and duplication removal will be disabled.
- The `-b` flag can be used to bypass map creation and use stdout as primary output. This can be useful for working with large datasets. If the `-b` flag is used, the final output will be empty and all filtering and duplication removal will be disabled.
- The `-d [0-2]` flag can be used to enable debug output. This will show the data
object after all transformations have been applied. There are two (2) levels
of debug output that can be used.
Expand All @@ -77,7 +75,7 @@ There are some additional notes when importing data:
template file should contain a list of transformations and operations to apply
to the input data. The template file should be in JSON format.
- See `docs/template.json` ([link](https://github.com/JakeWnuk/ptt/blob/main/docs/template.json)) for an example.
- See `docs/templates/` ([link](https://github.com/JakeWnuk/ptt/blob/main/docs/templates/)) for more examples.
- See `docs/templates/` ([link](https://github.com/JakeWnuk/ptt/blob/main/templates/)) for more examples.

The `-f`, `-k`, `-r`, `-tf`, `-tp`, and `-u` flags can be used multiple times and have
their collective values combined. The rest of the flags can only be used once.
Expand Down Expand Up @@ -175,6 +173,10 @@ keywords above:
- `ppt -l 8-12`: Keep only items within a range of lengths.
- `ptt -m 10`: Keep only items with a minimum frequency.

#### Debug Formats:
- `ptt -d 1`: Enable debug mode with verbosity level 1.
- `ptt -d 2`: Enable debug mode with verbosity level 2.

#### Output Formats:
- `ptt -v`: Show verbose output.
- `ptt -vv`: Show statistics output.
Expand Down
40 changes: 40 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
// - ReadFilesToMap()
// - LoadStdinToMap()
// - CombineMaps()
// - ReadJSONToArray()
//
// ** Transformation Functions **
// - ReverseString()
Expand Down Expand Up @@ -158,6 +159,45 @@ func TestCombineMaps(t *testing.T) {
}
}

// Unit Test for ReadJSONToArray()
func TestReadJSONToArray(t *testing.T) {
// Define a test case struct
type TestCase struct {
Input string
Output []models.TemplateFileOperation
}

type TestCases []TestCase

// Create a mock file system with example files
mockFs := &models.MockFileSystem{
Files: map[string][]byte{
"file1": []byte(`[{"StartIndex":0,"EndIndex":4,"Verbose":true,"ReplacementMask":"uldbs","Bypass":false,"TransformationMode":"append"}]`),
"file2": []byte(`[{"StartIndex":0,"EndIndex":4,"Verbose":true,"ReplacementMask":"uldbs","Bypass":false,"TransformationMode":"append"},{"StartIndex":0,"EndIndex":4,"Verbose":true,"ReplacementMask":"uldbs","Bypass":false,"TransformationMode":"append"}]`),
"file3": []byte(`[{"StartIndex":0,"EndIndex":4,"Verbose":true,"ReplacementMask":"uldbs","Bypass":false,"TransformationMode":"append"},{"StartIndex":0,"EndIndex":4,"Verbose":true,"ReplacementMask":"uldbs","Bypass":false,"TransformationMode":"append"},{"StartIndex":0,"EndIndex":4,"Verbose":true,"ReplacementMask":"uldbs","Bypass":false,"TransformationMode":"append"}]`),
},
}

// Define test cases
testCases := TestCases{
{"file1", []models.TemplateFileOperation{{StartIndex: 0, EndIndex: 4, Verbose: true, ReplacementMask: "uldbs", Bypass: false, TransformationMode: "append"}}},
{"file2", []models.TemplateFileOperation{{StartIndex: 0, EndIndex: 4, Verbose: true, ReplacementMask: "uldbs", Bypass: false, TransformationMode: "append"}, {StartIndex: 0, EndIndex: 4, Verbose: true, ReplacementMask: "uldbs", Bypass: false, TransformationMode: "append"}}},
{"file3", []models.TemplateFileOperation{{StartIndex: 0, EndIndex: 4, Verbose: true, ReplacementMask: "uldbs", Bypass: false, TransformationMode: "append"}, {StartIndex: 0, EndIndex: 4, Verbose: true, ReplacementMask: "uldbs", Bypass: false, TransformationMode: "append"}, {StartIndex: 0, EndIndex: 4, Verbose: true, ReplacementMask: "uldbs", Bypass: false, TransformationMode: "append"}}},
}

// Run test cases
for _, testCase := range testCases {
input := []string{testCase.Input}
output := testCase.Output

given := ReadJSONToArray(mockFs, input)
if given[0].StartIndex != output[0].StartIndex || given[0].EndIndex != output[0].EndIndex || given[0].Verbose != output[0].Verbose || given[0].ReplacementMask != output[0].ReplacementMask || given[0].Bypass != output[0].Bypass || given[0].TransformationMode != output[0].TransformationMode {
t.Errorf("ReadJSONToArray(%v) = %v; want %v", input, given, output)
}
}

}

// Unit Test for ReverseString()
func TestReverseString(t *testing.T) {

Expand Down