Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #88 from mycel-domain/feat/access-control
Browse files Browse the repository at this point in the history
Feat/access control
  • Loading branch information
Jaguarmouse authored Sep 15, 2023
2 parents aa9feba + d35ee3e commit ed87238
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 632 deletions.
129 changes: 67 additions & 62 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50067,10 +50067,12 @@ paths:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
pagination:
type: object
properties:
Expand Down Expand Up @@ -50275,10 +50277,12 @@ paths:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -50446,12 +50450,12 @@ paths:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
recordEditor:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
pagination:
type: object
properties:
Expand Down Expand Up @@ -50662,12 +50666,12 @@ paths:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
recordEditor:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -80486,6 +80490,13 @@ definitions:
type: string
parent:
type: string
mycel.registry.DomainRole:
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
mycel.registry.Fee:
type: object
properties:
Expand Down Expand Up @@ -80715,12 +80726,12 @@ definitions:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
recordEditor:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
pagination:
type: object
properties:
Expand Down Expand Up @@ -80840,10 +80851,12 @@ definitions:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
pagination:
type: object
properties:
Expand Down Expand Up @@ -81000,12 +81013,12 @@ definitions:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
recordEditor:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
mycel.registry.QueryGetTopLevelDomainResponse:
type: object
properties:
Expand Down Expand Up @@ -81097,10 +81110,12 @@ definitions:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
mycel.registry.QueryIsRegistrableDomainResponse:
type: object
properties:
Expand Down Expand Up @@ -81210,12 +81225,12 @@ definitions:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
recordEditor:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
mycel.registry.SubdomainConfig:
type: object
properties:
Expand Down Expand Up @@ -81343,13 +81358,6 @@ definitions:

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
mycel.registry.SubdomainRole:
type: object
properties:
owner:
type: string
recordEditor:
type: string
mycel.registry.TopLevelDomain:
type: object
properties:
Expand Down Expand Up @@ -81436,15 +81444,12 @@ definitions:
accessControl:
type: object
additionalProperties:
type: object
properties:
owner:
type: string
mycel.registry.TopLevelDomainRole:
type: object
properties:
owner:
type: string
type: string
enum:
- NO_ROLE
- OWNER
- EDITOR
default: NO_ROLE
mycel.registry.WalletRecord:
type: object
properties:
Expand Down
10 changes: 10 additions & 0 deletions proto/mycel/registry/role.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";
package mycel.registry;

option go_package = "github.com/mycel-domain/mycel/x/registry/types";

enum DomainRole {
NO_ROLE = 0;
OWNER = 1;
EDITOR = 2;
}
8 changes: 2 additions & 6 deletions proto/mycel/registry/second_level_domain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mycel.registry;

import "mycel/registry/dns_record.proto";
import "mycel/registry/network_name.proto";
import "mycel/registry/role.proto";

option go_package = "github.com/mycel-domain/mycel/x/registry/types";

Expand All @@ -17,11 +18,6 @@ message WalletRecord {
string value = 2;
}

message SubdomainRole {
string owner = 1;
string recordEditor = 2;
}

message SecondLevelDomain {
string name = 1;
string parent = 2;
Expand All @@ -30,5 +26,5 @@ message SecondLevelDomain {
map<string, DnsRecord> dnsRecords = 5;
map<string, WalletRecord> walletRecords = 6;
map<string, string> metadata = 7;
map<string, SubdomainRole> accessControl = 8;
map<string, DomainRole> accessControl = 8;
}
7 changes: 2 additions & 5 deletions proto/mycel/registry/top_level_domain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ syntax = "proto3";
package mycel.registry;

import "mycel/registry/subdomain_config.proto";
import "mycel/registry/role.proto";

option go_package = "github.com/mycel-domain/mycel/x/registry/types";

message TopLevelDomainRole {
string owner = 1;
}

message TopLevelDomain {
string name = 1;
int64 expirationDate = 2;
map<string, string> metadata = 3;
SubdomainConfig subdomainConfig = 4;
uint64 subdomainCount = 5;
map<string, TopLevelDomainRole> accessControl = 6;
map<string, DomainRole> accessControl = 6;
}
2 changes: 1 addition & 1 deletion x/registry/client/cli/query_second_level_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func networkWithSecondLevelDomainObjects(t *testing.T, n int) (*network.Network,
DnsRecords: make(map[string]*types.DnsRecord),
WalletRecords: make(map[string]*types.WalletRecord),
Metadata: make(map[string]string),
AccessControl: make(map[string]*types.SubdomainRole),
AccessControl: make(map[string]types.DomainRole),
}
nullify.Fill(&secondLevelDomain)
state.SecondLevelDomains = append(state.SecondLevelDomains, secondLevelDomain)
Expand Down
4 changes: 2 additions & 2 deletions x/registry/client/cli/query_top_level_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func networkWithTopLevelDomainObjects(t *testing.T, n int) (*network.Network, []
state := types.GenesisState{}
for i := 0; i < n; i++ {
topLevelDomain := types.TopLevelDomain{
Name: strconv.Itoa(i),
Name: strconv.Itoa(i),
Metadata: make(map[string]string),
AccessControl: make(map[string]*types.TopLevelDomainRole),
AccessControl: make(map[string]types.DomainRole),
}
nullify.Fill(&topLevelDomain)
state.TopLevelDomains = append(state.TopLevelDomains, topLevelDomain)
Expand Down
4 changes: 4 additions & 0 deletions x/registry/keeper/msg_server_register_second_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func (k msgServer) RegisterDomain(goCtx context.Context, msg *types.MsgRegisterD

currentTime := ctx.BlockTime()
expirationDate := currentTime.AddDate(int(msg.RegistrationPeriodInYear), 0, 0)
accessControl := map[string]types.DomainRole{
msg.Creator: types.DomainRole_OWNER,
}

domain := types.SecondLevelDomain{
Name: msg.Name,
Expand All @@ -34,6 +37,7 @@ func (k msgServer) RegisterDomain(goCtx context.Context, msg *types.MsgRegisterD
DnsRecords: nil,
WalletRecords: nil,
Metadata: nil,
AccessControl: accessControl,
}

err = k.Keeper.RegisterDomain(ctx, domain, creatorAddress, msg.RegistrationPeriodInYear)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() {
suite.Require().Equal(tc.domainOwnership, domainOwnership)

// Evalute if domain is registered
_, found = suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, tc.parent)
domain, found := suite.app.RegistryKeeper.GetSecondLevelDomain(suite.ctx, tc.name, tc.parent)
suite.Require().True(found)
suite.Require().Equal(domain.AccessControl[tc.creator], types.DomainRole_OWNER)

// // Evalute if parent's subdomainCount is increased
// parent, found = suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, parentsName)
Expand Down
4 changes: 4 additions & 0 deletions x/registry/keeper/msg_server_register_top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ func (k msgServer) RegisterTopLevelDomain(goCtx context.Context, msg *types.MsgR

currentTime := ctx.BlockTime()
expirationDate := currentTime.AddDate(int(msg.RegistrationPeriodInYear), 0, 0)
accessControl := map[string]types.DomainRole{
msg.Creator: types.DomainRole_OWNER,
}

defaultRegistrationConfig := types.GetDefaultSubdomainConfig(3030)
domain := types.TopLevelDomain{
Name: msg.Name,
ExpirationDate: expirationDate.UnixNano(),
Metadata: nil,
SubdomainConfig: &defaultRegistrationConfig,
AccessControl: accessControl,
}

err = k.Keeper.RegisterTopLevelDomain(ctx, domain, creatorAddress, msg.RegistrationPeriodInYear)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ func (suite *KeeperTestSuite) TestRegisterTopLevelDomain() {

if tc.expErr == nil {
// Evalute if domain is registered
_, found := suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, tc.name)
domain, found := suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, tc.name)
suite.Require().True(found)
suite.Require().Equal(domain.AccessControl[tc.creator], types.DomainRole_OWNER)

// Evalute events
suite.Require().Nil(err)
Expand Down
7 changes: 4 additions & 3 deletions x/registry/keeper/msg_server_update_dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ func (k msgServer) UpdateDnsRecord(goCtx context.Context, msg *types.MsgUpdateDn
}

// Check if the domain is owned by the creator
if domain.Owner != msg.Creator {
return nil, sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s.%s", msg.Name, msg.Parent)), types.ErrDomainNotOwned.Error())
isEditable, err := domain.IsRecordEditable(msg.Creator)
if !isEditable {
return nil, err
}

err := domain.UpdateDnsRecord(msg.DnsRecordType, msg.Value)
err = domain.UpdateDnsRecord(msg.DnsRecordType, msg.Value)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/registry/keeper/msg_server_update_dns_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (suite *KeeperTestSuite) TestUpdateDnsRecord() {
parent: "cel",
dnsRecordType: "A",
value: "192.168.0.1",
expErr: sdkerrors.Wrapf(errors.New(fmt.Sprintf("foo.cel")), types.ErrDomainNotOwned.Error()),
expErr: sdkerrors.Wrapf(errors.New(fmt.Sprintf(testutil.Bob)), types.ErrDomainNotEditable.Error()),
fn: func() {},
},
}
Expand Down
7 changes: 4 additions & 3 deletions x/registry/keeper/msg_server_update_wallet_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ func (k msgServer) UpdateWalletRecord(goCtx context.Context, msg *types.MsgUpdat
}

// Check if the domain is owned by the creator
if domain.Owner != msg.Creator {
return nil, sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s.%s", msg.Name, msg.Parent)), types.ErrDomainNotOwned.Error())
isEditable, err := domain.IsRecordEditable(msg.Creator)
if !isEditable {
return nil, err
}

err := domain.UpdateWalletRecord(msg.WalletRecordType, msg.Value)
err = domain.UpdateWalletRecord(msg.WalletRecordType, msg.Value)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit ed87238

Please sign in to comment.