-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7872ef5
commit bc0ae89
Showing
7 changed files
with
186 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package httpserver | ||
|
||
import ( | ||
"fmt" | ||
"github.com/go-errors/errors" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestValidateFiles(t *testing.T) { | ||
table := []struct { | ||
name string | ||
privateKeyFile string | ||
certFile string | ||
wantOutput interface{} | ||
wantErr error | ||
}{ | ||
{ | ||
name : "normal file names", | ||
privateKeyFile: "key", | ||
certFile: "cert", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name : "error in both privatekey and certfile filenames", | ||
privateKeyFile: "--cert-file", | ||
certFile: "-l", | ||
wantErr: errors.Errorf("error with --key-path flag value: %s, error with --cert-path flag value: %s", | ||
fmt.Sprintf("file name inappropriate: %s", "--cert-file"), | ||
fmt.Sprintf("file name inappropriate: %s", "-l")), | ||
}, | ||
{ | ||
name: "error in privatekey filename", | ||
privateKeyFile: "--cert-file", | ||
certFile: "certfile", | ||
wantErr: errors.Errorf("error with --key-path flag value: %s", | ||
fmt.Sprintf("file name inappropriate: %s", "--cert-file")), | ||
}, | ||
{ | ||
name: "error in certfile filename", | ||
privateKeyFile: "keyfile", | ||
certFile: "--wrong-name", | ||
wantErr: errors.Errorf("error with --cert-path flag value: %s", | ||
fmt.Sprintf("file name inappropriate: %s", "--wrong-name")), | ||
}, | ||
} | ||
|
||
for _, tt := range table { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotErr := validateFiles(tt.privateKeyFile, tt.certFile) | ||
if !reflect.DeepEqual(gotErr, tt.wantErr) { | ||
if tt.wantErr != nil && gotErr != nil && tt.wantErr.Error() != gotErr.Error() { | ||
t.Errorf("error got: '%v', want: '%v'", gotErr, tt.wantErr) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package utils | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"strings" | ||
) | ||
|
||
func ValidateFileName(file string) error { | ||
if strings.HasPrefix(file, "-") { | ||
return errors.Errorf("file name inappropriate: %s", file) | ||
} | ||
return nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package utils | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestValidateFileName(t *testing.T) { | ||
|
||
table := []struct { | ||
name string | ||
filename string | ||
wantErr error | ||
}{ | ||
{ | ||
name : "normal file names", | ||
filename: "key", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name : "-- prefix in the filename", | ||
filename: "--cert-file", | ||
wantErr: errors.Errorf("file name inappropriate: %s", "--cert-file"), | ||
}, | ||
{ | ||
name : "- prefix in the filename", | ||
filename: "-c", | ||
wantErr: errors.Errorf("file name inappropriate: %s", "-c"), | ||
}, | ||
|
||
} | ||
|
||
for _, tt := range table { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotErr := ValidateFileName(tt.filename) | ||
if !reflect.DeepEqual(gotErr, tt.wantErr) { | ||
if tt.wantErr != nil && gotErr != nil && tt.wantErr.Error() != gotErr.Error() { | ||
t.Errorf("error got: '%v', want: '%v'", gotErr, tt.wantErr) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIID9TCCAt2gAwIBAgIJANcasjhanWjaMA0GCSqGSIb3DQEBCwUAMIGeMQswCQYD | ||
VQQGEwJJTjEUMBIGA1UECAwLTWFoYXJhc2h0cmExDTALBgNVBAcMBFB1bmUxETAP | ||
BgNVBAoMCEFjY3VyaWNzMScwJQYJKoZIhvcNAQkBFhhkZXZhbmcuZ2F1ckBhY2N1 | ||
cmljcy5jb20xLjAsBgNVBAMMJXRlcnJhc2Nhbi50ZXJyYXNjYW4uc3ZjLmNsdXN0 | ||
ZXIubG9jYWwwHhcNMjEwNTEwMjIzMTM0WhcNMjEwNjA5MjIzMTM0WjCBnjELMAkG | ||
A1UEBhMCSU4xFDASBgNVBAgMC01haGFyYXNodHJhMQ0wCwYDVQQHDARQdW5lMREw | ||
DwYDVQQKDAhBY2N1cmljczEnMCUGCSqGSIb3DQEJARYYZGV2YW5nLmdhdXJAYWNj | ||
dXJpY3MuY29tMS4wLAYDVQQDDCV0ZXJyYXNjYW4udGVycmFzY2FuLnN2Yy5jbHVz | ||
dGVyLmxvY2FsMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnph3od0J | ||
zp3RI8eQx488YVWIlBbqGZChDxoS8aadmBc+clM2ZPnEDfgsOvCe8UL0uG//waC1 | ||
UzNoXe5ThhsqD8avrlfqxYQk+PGcaf/iOOEMN9+G+rUmqm1zKkVPRkHjtMXvGUHb | ||
lwULA0qMlvW24noWPXS+D+6cv90pFxP+2Xkh4FnDE63pXrQ+2Gf2hNVDMNaeiTP9 | ||
zPnyBE+6Pd5uLAMHrBpwkC9M39yhnLx1vlKO/XnOQGXANpItVHO8HsbKT+o6fbPI | ||
/RshvNi7rq1mPBcbq/gwTs68RpafdXDKIWMOZDpMVOto5+B2DRMHIvZ/BW4y5Ip0 | ||
+wI2kXw8UlrHkQIDAQABozQwMjAwBgNVHREEKTAngiV0ZXJyYXNjYW4udGVycmFz | ||
Y2FuLnN2Yy5jbHVzdGVyLmxvY2FsMA0GCSqGSIb3DQEBCwUAA4IBAQAGHoZvgZwd | ||
dLbaZaVT6jfZLqZxz2g004/sK9z4U6bcXTeXx5nJUsE4RkCVt+wAsH1eNF8Xdr7c | ||
rMTH5mcHYcpcRH1CBktYkMF5nZwLzjRoR5abju0BZWrsEZi7cDJOeboW6EQqFBn8 | ||
LFsG2437Lx8to8XYheo91HG3QFdFo2kofaelUAqIxz0WdPnjChPH7RpjUEubXn1+ | ||
VKKrFhB6zKulU+YJaEJ0LO38CejrwKRT+pr1v3HaWnJSitZaJDDwxvkvSjdf8Rk2 | ||
4HsU1Rp2v3ts1zfzUthWrnc3G8darZx5ZdQWjRK2C17zrtzJO7M33D8BjiQaTQXL | ||
kCfVMzBQKmOp | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCemHeh3QnOndEj | ||
x5DHjzxhVYiUFuoZkKEPGhLxpp2YFz5yUzZk+cQN+Cw68J7xQvS4b//BoLVTM2hd | ||
7lOGGyoPxq+uV+rFhCT48Zxp/+I44Qw334b6tSaqbXMqRU9GQeO0xe8ZQduXBQsD | ||
SoyW9bbiehY9dL4P7py/3SkXE/7ZeSHgW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