-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
3 changed files
with
98 additions
and
0 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
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,63 @@ | ||
package signature_header_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
signature_header "github.com/cloudmatelabs/go-activitypub-signature-header" | ||
) | ||
|
||
var ( | ||
keyId = `https://snippet.social/@juunini#main-key` | ||
algorithm = `rsa-sha256` | ||
_headers = `(request-target) date host digest` | ||
signatureHash = "g99dh20dygasd==" | ||
) | ||
|
||
var signature = strings.Join([]string{ | ||
fmt.Sprintf(`keyId="%s"`, keyId), | ||
fmt.Sprintf(`algorithm="%s"`, algorithm), | ||
fmt.Sprintf(`headers="%s"`, headers), | ||
fmt.Sprintf(`signature="%s"`, signatureHash), | ||
}, ",") | ||
|
||
func Test_ParseSignature(t *testing.T) { | ||
params := signature_header.ParseSignature(signature) | ||
|
||
if params["algorithm"] != algorithm { | ||
t.Errorf("Algorithm is not correct: %s", params["algorithm"]) | ||
} | ||
|
||
if params["keyId"] != keyId { | ||
t.Errorf("KeyID is not correct: %s", params["keyId"]) | ||
} | ||
|
||
if params["signature"] != signatureHash { | ||
t.Errorf("Signature is not correct: %s", params["signature"]) | ||
} | ||
|
||
if params["headers"] != _headers { | ||
t.Errorf("Headers is not correct: %s", params["headers"]) | ||
} | ||
} | ||
|
||
func Test_ParseSignature_WithAuthorization(t *testing.T) { | ||
params := signature_header.ParseSignature("Signature " + signature) | ||
|
||
if params["algorithm"] != algorithm { | ||
t.Errorf("Algorithm is not correct: %s", params["algorithm"]) | ||
} | ||
|
||
if params["keyId"] != keyId { | ||
t.Errorf("KeyID is not correct: %s", params["keyId"]) | ||
} | ||
|
||
if params["signature"] != signatureHash { | ||
t.Errorf("Signature is not correct: %s", params["signature"]) | ||
} | ||
|
||
if params["headers"] != _headers { | ||
t.Errorf("Headers is not correct: %s", params["headers"]) | ||
} | ||
} |