|
|
@@ -6,7 +6,7 @@ import (
|
|
|
"crypto/x509"
|
|
|
"encoding/pem"
|
|
|
"fmt"
|
|
|
- config2 "github.com/OliveTin/OliveTin/internal/config"
|
|
|
+ config "github.com/OliveTin/OliveTin/internal/config"
|
|
|
"github.com/OliveTin/OliveTin/internal/cors"
|
|
|
"github.com/golang-jwt/jwt/v4"
|
|
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
|
|
@@ -22,7 +22,7 @@ import (
|
|
|
|
|
|
func createKeys() (*rsa.PrivateKey, string) {
|
|
|
tmpFile, _ := os.CreateTemp(os.TempDir(), "olivetin-jwt-")
|
|
|
- //defer os.Remove(tmpFile.Name())
|
|
|
+ defer os.Remove(tmpFile.Name())
|
|
|
|
|
|
fmt.Println("Created File: " + tmpFile.Name())
|
|
|
|
|
|
@@ -48,12 +48,12 @@ func testBase(t *testing.T, expire int64, expectCode int) {
|
|
|
privateKey, publicKeyPath := createKeys()
|
|
|
|
|
|
// default config + overrides
|
|
|
- config := config2.DefaultConfig()
|
|
|
- config.AuthJwtPubKeyPath = publicKeyPath
|
|
|
- config.AuthJwtClaimUsername = "sub"
|
|
|
- config.AuthJwtClaimUserGroup = "olivetinGroup"
|
|
|
- config.AuthJwtCookieName = "authorization_token"
|
|
|
- SetGlobalRestConfig(config) // ugly, setting global var, we should pass configs as params to modules... :/
|
|
|
+ cfg := config.DefaultConfig()
|
|
|
+ cfg.AuthJwtPubKeyPath = publicKeyPath
|
|
|
+ cfg.AuthJwtClaimUsername = "sub"
|
|
|
+ cfg.AuthJwtClaimUserGroup = "olivetinGroup"
|
|
|
+ cfg.AuthJwtCookieName = "authorization_token"
|
|
|
+ SetGlobalRestConfig(cfg) // ugly, setting global var, we should pass configs as params to modules... :/
|
|
|
|
|
|
token := jwt.New(jwt.SigningMethodRS256)
|
|
|
|
|
|
@@ -87,16 +87,16 @@ func testBase(t *testing.T, expire int64, expectCode int) {
|
|
|
|
|
|
// make server and attach handler
|
|
|
srv := &http.Server{Handler: cors.AllowCors(mux)}
|
|
|
- lis, err := net.Listen("tcp", ":1337")
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- t.Errorf("Could not listen %v", err)
|
|
|
- }
|
|
|
+ lis, _ := net.Listen("tcp", ":1337")
|
|
|
|
|
|
/*
|
|
|
- if srv == nil {
|
|
|
- y.Errorf("srv is nil. Could not listen %v", err)
|
|
|
- }
|
|
|
+ if err != nil {
|
|
|
+ t.Errorf("Could not listen %v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if srv == nil {
|
|
|
+ y.Errorf("srv is nil. Could not listen %v", err)
|
|
|
+ }
|
|
|
*/
|
|
|
|
|
|
go func() {
|
|
|
@@ -127,7 +127,7 @@ func testBase(t *testing.T, expire int64, expectCode int) {
|
|
|
}
|
|
|
|
|
|
func TestJWTSignatureVerificationSucceeds(t *testing.T) {
|
|
|
-// testBase(t, 1000, 200)
|
|
|
+ //testBase(t, 1000, 200)
|
|
|
}
|
|
|
|
|
|
func TestJWTSignatureVerificationFails(t *testing.T) {
|