Skip to content

Commit 99a2e3f

Browse files
author
Shriram
committed
updated action
1 parent ec6c9d2 commit 99a2e3f

File tree

2 files changed

+194
-222
lines changed

2 files changed

+194
-222
lines changed

.github/workflows/go.yml

Lines changed: 194 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,206 @@
1-
# This workflow will build a golang project
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3-
41
name: Go
52

63
on:
74
push:
8-
branches: [ "main" ]
5+
branches: ["main"]
96
pull_request:
10-
branches: [ "main" ]
7+
branches: ["main"]
118

129
jobs:
13-
14-
build:
10+
test:
1511
runs-on: ubuntu-latest
1612
steps:
17-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: "1.23"
19+
20+
- name: Build
21+
run: |
22+
go build -o file-encryptor cmd/file-encryptor/main.go
23+
# Verify the binary was created
24+
ls -l file-encryptor
25+
# Make it executable
26+
chmod +x file-encryptor
27+
28+
- name: Prepare Test Files
29+
run: |
30+
# Create a text file with specific content
31+
echo "This is a test file with special characters: !@#$%^&*()" > test.txt
32+
33+
# Create a binary file
34+
dd if=/dev/urandom of=binary.dat bs=1024 count=100
35+
36+
# Create a JSON file
37+
echo '{"test": "data", "number": 123}' > data.json
38+
39+
echo "Created test files:"
40+
ls -l test.txt binary.dat data.json
41+
echo "test.txt content:"
42+
cat test.txt
43+
echo "data.json content:"
44+
cat data.json
45+
echo "binary.dat sha256sum:"
46+
sha256sum binary.dat
47+
48+
- name: Test RSA Key Generation
49+
run: |
50+
pwd
51+
ls -la
52+
./file-encryptor --generate-keys --key-name test_key
53+
if [ ! -f test_key_private_*.key ] || [ ! -f test_key_public_*.pub ]; then
54+
echo "Failed to generate key pair"
55+
exit 1
56+
fi
57+
echo "Generated RSA key pair successfully"
58+
ls -l test_key_*
59+
60+
- name: Test RSA Encryption and Decryption - Text File
61+
run: |
62+
# Store original content
63+
ORIGINAL_CONTENT=$(cat test.txt)
64+
65+
# Encrypt
66+
./file-encryptor -e -f test.txt -k test_key_public_*.pub
67+
if [ ! -f test.txt.enc ]; then
68+
echo "Encryption failed - no output file"
69+
exit 1
70+
fi
71+
72+
rm test.txt
73+
74+
# Decrypt
75+
./file-encryptor -d -f test.txt.enc -k test_key_private_*.key
76+
77+
# Verify content
78+
DECRYPTED_CONTENT=$(cat test.txt)
79+
if [ "$ORIGINAL_CONTENT" != "$DECRYPTED_CONTENT" ]; then
80+
echo "Content mismatch after RSA encryption/decryption"
81+
echo "Original: $ORIGINAL_CONTENT"
82+
echo "Decrypted: $DECRYPTED_CONTENT"
83+
exit 1
84+
fi
85+
echo "RSA encryption/decryption for text file verified successfully"
86+
87+
- name: Test RSA Encryption and Decryption - Binary File
88+
run: |
89+
# Store original hash
90+
ORIGINAL_HASH=$(sha256sum binary.dat | awk '{print $1}')
91+
92+
# Encrypt
93+
./file-encryptor -e -f binary.dat -k test_key_public_*.pub
94+
if [ ! -f binary.dat.enc ]; then
95+
echo "Encryption failed - no output file"
96+
exit 1
97+
fi
98+
99+
rm binary.dat
100+
101+
# Decrypt
102+
./file-encryptor -d -f binary.dat.enc -k test_key_private_*.key
103+
104+
# Verify hash
105+
DECRYPTED_HASH=$(sha256sum binary.dat | awk '{print $1}')
106+
if [ "$ORIGINAL_HASH" != "$DECRYPTED_HASH" ]; then
107+
echo "Hash mismatch after RSA encryption/decryption"
108+
echo "Original hash: $ORIGINAL_HASH"
109+
echo "Decrypted hash: $DECRYPTED_HASH"
110+
exit 1
111+
fi
112+
echo "RSA encryption/decryption for binary file verified successfully"
113+
114+
- name: Test Password Encryption and Decryption - JSON File
115+
run: |
116+
# Store original content
117+
ORIGINAL_CONTENT=$(cat data.json)
118+
119+
# Encrypt
120+
./file-encryptor -e -f data.json -p "TestPassword123!"
121+
if [ ! -f data.json.enc ]; then
122+
echo "Encryption failed - no output file"
123+
exit 1
124+
fi
125+
rm data.json
126+
# Decrypt
127+
./file-encryptor -d -f data.json.enc -p "TestPassword123!"
128+
129+
# Verify content
130+
DECRYPTED_CONTENT=$(cat data.json)
131+
if [ "$ORIGINAL_CONTENT" != "$DECRYPTED_CONTENT" ]; then
132+
echo "Content mismatch after password encryption/decryption"
133+
echo "Original: $ORIGINAL_CONTENT"
134+
echo "Decrypted: $DECRYPTED_CONTENT"
135+
exit 1
136+
fi
137+
echo "Password encryption/decryption for JSON file verified successfully"
138+
139+
- name: Test Generate-and-Encrypt with Decryption
140+
run: |
141+
# Store original content
142+
ORIGINAL_CONTENT=$(cat test.txt)
143+
144+
# Generate keys and encrypt in one step
145+
./file-encryptor --generate-keys -e -f test.txt
146+
147+
# Get the latest generated private key
148+
PRIVATE_KEY=$(ls -t key_private_*.key | head -1)
149+
150+
rm test.txt
151+
152+
# Decrypt using generated key
153+
./file-encryptor -d -f test.txt.enc -k "$PRIVATE_KEY"
154+
155+
# Verify content
156+
DECRYPTED_CONTENT=$(cat test.txt)
157+
if [ "$ORIGINAL_CONTENT" != "$DECRYPTED_CONTENT" ]; then
158+
echo "Content mismatch after generate-and-encrypt"
159+
echo "Original: $ORIGINAL_CONTENT"
160+
echo "Decrypted: $DECRYPTED_CONTENT"
161+
exit 1
162+
fi
163+
echo "Generate-and-encrypt with decryption verified successfully"
164+
165+
- name: Test Wrong Password Scenario
166+
run: |
167+
# Attempt to decrypt with wrong password
168+
if ./file-encryptor -d -f data.json.enc -p "WrongPassword123!"; then
169+
echo "Decryption with wrong password succeeded when it should fail"
170+
exit 1
171+
fi
172+
echo "Wrong password test passed successfully"
173+
174+
- name: Test File Extension Preservation
175+
run: |
176+
# Create test files with different extensions
177+
echo "Test content" > test.doc
178+
echo "Test content" > test.pdf
179+
180+
# Encrypt files
181+
./file-encryptor -e -f test.doc -p "TestPassword123!"
182+
./file-encryptor -e -f test.pdf -p "TestPassword123!"
18183
19-
- name: Set up Go
20-
uses: actions/setup-go@v5
21-
with:
22-
go-version: '1.23'
184+
# Decrypt files
185+
./file-encryptor -d -f test.doc.enc -p "TestPassword123!"
186+
./file-encryptor -d -f test.pdf.enc -p "TestPassword123!"
23187
24-
- name: Build
25-
run: go build -v ./...
188+
# Verify extensions
189+
if [ ! -f test.doc]; then
190+
echo "Failed to preserve .doc extension"
191+
exit 1
192+
fi
193+
if [ ! -f test.pdf ]; then
194+
echo "Failed to preserve .pdf extension"
195+
exit 1
196+
fi
197+
echo "File extension preservation test passed successfully"
26198
27-
- name: Test
28-
run: go test -v ./...
199+
- name: Cleanup
200+
run: |
201+
rm -f test.txt test.txt.enc test.txt.dec
202+
rm -f binary.dat binary.dat.enc binary.dat
203+
rm -f data.json data.json.enc data.json
204+
rm -f test.doc* test.pdf*
205+
rm -f test_key_* key_*
206+
echo "Cleanup completed"

0 commit comments

Comments
 (0)