-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ip whitelisting * refactor(key_verify.go): remove unnecessary logging statement refactor(server.go): reformat fiber.Config initialization for better readability
- Loading branch information
Showing
22 changed files
with
501 additions
and
65 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
File renamed without changes.
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,69 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/unkeyed/unkey/apps/api/pkg/entities" | ||
"github.com/unkeyed/unkey/apps/api/pkg/logging" | ||
"github.com/unkeyed/unkey/apps/api/pkg/uid" | ||
) | ||
|
||
func TestApiSetGet_Simple(t *testing.T) { | ||
ctx := context.Background() | ||
db, err := New(Config{ | ||
Logger: logging.NewNoopLogger(), | ||
PrimaryUs: os.Getenv("DATABASE_DSN"), | ||
}) | ||
|
||
require.NoError(t, err) | ||
|
||
api := entities.Api{ | ||
Id: uid.Api(), | ||
Name: "test", | ||
WorkspaceId: uid.Workspace(), | ||
} | ||
|
||
err = db.CreateApi(ctx, api) | ||
require.NoError(t, err) | ||
|
||
found, err := db.GetApi(ctx, api.Id) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, api.Id, found.Id) | ||
require.Equal(t, api.Name, found.Name) | ||
require.Equal(t, api.WorkspaceId, found.WorkspaceId) | ||
require.Equal(t, 0, len(found.IpWhitelist)) | ||
|
||
} | ||
|
||
func TestApiSetGet_WithIpWhitelist(t *testing.T) { | ||
ctx := context.Background() | ||
db, err := New(Config{ | ||
Logger: logging.NewNoopLogger(), | ||
PrimaryUs: os.Getenv("DATABASE_DSN"), | ||
}) | ||
|
||
require.NoError(t, err) | ||
|
||
api := entities.Api{ | ||
Id: uid.Api(), | ||
Name: "test", | ||
WorkspaceId: uid.Workspace(), | ||
IpWhitelist: []string{"1.1.1.1", "2.2.2.2"}, | ||
} | ||
|
||
err = db.CreateApi(ctx, api) | ||
require.NoError(t, err) | ||
|
||
found, err := db.GetApi(ctx, api.Id) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, api.Id, found.Id) | ||
require.Equal(t, api.Name, found.Name) | ||
require.Equal(t, api.WorkspaceId, found.WorkspaceId) | ||
require.Equal(t, api.IpWhitelist, found.IpWhitelist) | ||
|
||
} |
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,82 @@ | ||
package database | ||
|
||
import ( | ||
"database/sql" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/unkeyed/unkey/apps/api/pkg/database/models" | ||
"github.com/unkeyed/unkey/apps/api/pkg/entities" | ||
"github.com/unkeyed/unkey/apps/api/pkg/uid" | ||
) | ||
|
||
func Test_apiEntityToModel(t *testing.T) { | ||
e := entities.Api{ | ||
Id: uid.Api(), | ||
Name: "test", | ||
WorkspaceId: uid.Workspace(), | ||
} | ||
|
||
m := apiEntityToModel(e) | ||
|
||
require.Equal(t, e.Id, m.ID) | ||
require.Equal(t, e.Name, m.Name) | ||
require.Equal(t, e.WorkspaceId, m.WorkspaceID) | ||
require.Equal(t, false, m.IPWhitelist.Valid) | ||
require.Equal(t, "", m.IPWhitelist.String) | ||
|
||
} | ||
|
||
func Test_apiModelToEntity(t *testing.T) { | ||
|
||
m := &models.API{ | ||
ID: uid.Api(), | ||
Name: "test", | ||
WorkspaceID: uid.Workspace(), | ||
} | ||
|
||
e := apiModelToEntity(m) | ||
|
||
require.Equal(t, m.ID, e.Id) | ||
require.Equal(t, m.Name, e.Name) | ||
require.Equal(t, m.WorkspaceID, e.WorkspaceId) | ||
require.Equal(t, 0, len(e.IpWhitelist)) | ||
} | ||
|
||
func Test_apiEntityToModel_WithIpWithlist(t *testing.T) { | ||
e := entities.Api{ | ||
Id: uid.Api(), | ||
Name: "test", | ||
WorkspaceId: uid.Workspace(), | ||
IpWhitelist: []string{"1.1.1.1", "2.2.2.2"}, | ||
} | ||
|
||
m := apiEntityToModel(e) | ||
|
||
require.Equal(t, e.Id, m.ID) | ||
require.Equal(t, e.Name, m.Name) | ||
require.Equal(t, e.WorkspaceId, m.WorkspaceID) | ||
require.Equal(t, true, m.IPWhitelist.Valid) | ||
require.Equal(t, "1.1.1.1,2.2.2.2", m.IPWhitelist.String) | ||
|
||
} | ||
|
||
func Test_apiModelToEntity_WithIpWithlist(t *testing.T) { | ||
|
||
m := &models.API{ | ||
ID: uid.Api(), | ||
Name: "test", | ||
WorkspaceID: uid.Workspace(), | ||
IPWhitelist: sql.NullString{ | ||
Valid: true, | ||
String: "1.1.1.1,2.2.2.2", | ||
}, | ||
} | ||
|
||
e := apiModelToEntity(m) | ||
|
||
require.Equal(t, m.ID, e.Id) | ||
require.Equal(t, m.Name, e.Name) | ||
require.Equal(t, m.WorkspaceID, e.WorkspaceId) | ||
require.Equal(t, []string{"1.1.1.1", "2.2.2.2"}, e.IpWhitelist) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Oops, something went wrong.
a9cd5e7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
unkey – ./
www.unkey.dev
unkey.dev
unkey.vercel.app
unkey-git-main-unkey.vercel.app
unkey-unkey.vercel.app