-
Notifications
You must be signed in to change notification settings - Fork 512
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
bc0ae89
commit e45a147
Showing
7 changed files
with
81 additions
and
145 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 was deleted.
Oops, something went wrong.
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,16 @@ | ||
package httpserver | ||
|
||
import "fmt" | ||
|
||
func (g *APIServer) validateFiles(privateKeyFile, certFile string) error { | ||
keylength := len(privateKeyFile) | ||
certlength := len(certFile) | ||
|
||
if keylength > 0 && certlength == 0 { | ||
return fmt.Errorf("private key file provided but certficate file missing") | ||
} else if keylength == 0 && certlength > 0 { | ||
return fmt.Errorf("certificate file provided but private key file missing") | ||
} | ||
|
||
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,54 @@ | ||
package httpserver | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestValidateFiles(t *testing.T) { | ||
server := APIServer{} | ||
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: "", | ||
certFile: "server.crt", | ||
wantErr: fmt.Errorf("certificate file provided but private key file missing"), | ||
}, | ||
{ | ||
name: "error in privatekey filename", | ||
privateKeyFile: "", | ||
certFile: "", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "error in certfile filename", | ||
privateKeyFile: "keyfile", | ||
certFile: "", | ||
wantErr: fmt.Errorf("private key file provided but certficate file missing"), | ||
}, | ||
} | ||
|
||
for _, tt := range table { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotErr := server.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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.