-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add -cert-file, -key-file and -p12-file (#77)
- Loading branch information
1 parent
0d0636e
commit 5ea72c3
Showing
3 changed files
with
123 additions
and
14 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,72 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
// TestGetFileName test func getFileName | ||
func TestGetFileName(t *testing.T) { | ||
// all flags are added | ||
mk := &mkcert{ | ||
keyFileFlag: "test-key-name.pem", | ||
certFileFlag: "test-cert-name.pem", | ||
p12FileFlag: "test.p12", | ||
} | ||
// check keyname, the result should be customized | ||
keyname, err := mk.getFileName("key", []string{"example.com"}) | ||
if err != nil { | ||
t.Error("failed to get customized key file name") | ||
} | ||
if keyname != "test-key-name.pem" { | ||
t.Error("keyname check failed") | ||
} | ||
|
||
// check certname, the result should be customized | ||
certname, err := mk.getFileName("cert", []string{"example.com"}) | ||
if err != nil { | ||
t.Error("failed to get customized cert file name") | ||
} | ||
if certname != "test-cert-name.pem" { | ||
t.Error("certname check failed") | ||
} | ||
|
||
// check p12name, the result should be customized | ||
p12name, err := mk.getFileName("p12", []string{"example.com"}) | ||
if err != nil { | ||
t.Error("failed to get customized p12 file name") | ||
} | ||
if p12name != "test.p12" { | ||
t.Error("p12 check failed") | ||
} | ||
|
||
// default name will be generated if no flags passed | ||
mk = &mkcert{ | ||
keyFileFlag: "test-key-name.pem", | ||
} | ||
// check keyname again, the result should be custoomized due to keyFileFlag | ||
keyname, err = mk.getFileName("key", []string{"example.com", "localhost"}) | ||
if err != nil { | ||
t.Error("failed to get customized key file name") | ||
} | ||
if keyname != "test-key-name.pem" { | ||
t.Error("keyname check failed") | ||
} | ||
|
||
// check default certname, the result should be default file name generated by original principle | ||
certname, err = mk.getFileName("cert", []string{"*.example.com", "localhost"}) | ||
if err != nil { | ||
t.Error("failed to get default cert file name") | ||
} | ||
if certname != "_wildcard.example.com+1.pem" { | ||
t.Error("certname check failed") | ||
} | ||
|
||
// check default p12name, the result should be default file name generated by original principle | ||
p12name, err = mk.getFileName("p12", []string{"x.co:y.com"}) | ||
if err != nil { | ||
t.Error("failed to get default p12 file name") | ||
} | ||
if p12name != "x.co_y.com.p12" { | ||
t.Error("p12 check failed") | ||
} | ||
} |
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