Skip to content

Conversation

@danielradu10
Copy link
Contributor

No description provided.

@sstanculeanu sstanculeanu self-requested a review May 5, 2025 08:24
{Name: "/sign-multiple-transactions", Open: true},
{Name: "/set-security-mode", Open: true},
{Name: "/unset-security-mode", Open: true},
{Name: "/security-status", Open: true},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this can be extended in the future, perhaps we rename it to something more generic like user-status

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed it

logUserStatusRequest(userIp, userAgent, &request, debugErr)
}()

err := json.NewDecoder(c.Request.Body).Decode(&request)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think request body and UserStatusRequest is needed here.. perhaps it can be something similar to node's /address/:address endpoint instead (/guardian/user-status/erd1....)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

{ Name = "/sign-multiple-transactions", Open = true, Auth = false, MaxContentLength = 1500000 },
{ Name = "/set-security-mode", Open = true, Auth = false, MaxContentLength = 200 },
{ Name = "/unset-security-mode", Open = true, Auth = false, MaxContentLength = 200 },
{ Name = "/security-status", Open = true, Auth = false, MaxContentLength = 200 },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaxContentLength not needed, it does not apply for get requests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

// NoExpiryValue is the returned value for a persistent key expiry time
const NoExpiryValue = -1

type Status int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comments on new fields

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

UserAddr string `json:"user"`
}

// UserStatusResponse - is the JSON response for the user status interrogation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// UserStatusResponse - is the JSON response for the user status interrogation
// UserStatusResponse is the JSON response for the user status request

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return resolver.verifyCodesReturningGuardian(userAddress, txs[0].GuardianAddr, userIp, code, secondCode)
}

func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) {
func (resolver *serviceResolver) getUserStatus(userAddr string) (core.Status, error) {

no verification done here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed it

func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) {
userAddress, err := sdkData.NewAddressFromBech32String(userAddr)
if err != nil {
return 0, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0, err
return core.NotSet, err

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed now

Comment on lines 503 to 509
addressBytes := userAddress.AddressBytes()
resolver.userCritSection.RLock(string(addressBytes))
_, err = resolver.getUserInfo(addressBytes)
resolver.userCritSection.RUnlock(string(addressBytes))
if err != nil {
return -1, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be removed 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it now

if r.GetSecurityStatusCalled != nil {
return r.GetSecurityStatusCalled(key)
}
return -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return -1
return core.NotSet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


// GetSecurityStatus -
func (r *RateLimiterMock) GetSecurityStatus(key string) core.Status {
return 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0
return core.NotSet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

signMultipleTransactionsPath = "/sign-multiple-transactions"
setSecurityModeNoExpirePath = "/set-security-mode"
unsetSecurityModeNoExpirePath = "/unset-security-mode"
getSecurityStatus = "/security-status"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to getSecurityStatusPath?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

Comment on lines 34 to 39
type Status int

const (
NotSet Status = iota
ManualSet
AutomaticallySet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add missing comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these changes needed? did you run go mod tidy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

return totp.rateLimiter.UnsetSecurityModeNoExpire(key)
}

// GetSecurityStatus - returns the status of the security mode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// GetSecurityStatus - returns the status of the security mode
// GetSecurityStatus returns the status of the security mode

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

_, err = resolver.getUserInfo(addressBytes)
resolver.userCritSection.RUnlock(string(addressBytes))
if err != nil {
return -1, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what -1 means here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set it as a error value, not needed it anymore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this -1 still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, all those lines are removed now.


// swagger:route GET /security-status Guardian getSecurityStatus
// Returns the security status.
// swagger:route GET /user-status Guardian getSecurityStatus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// swagger:route GET /user-status Guardian getSecurityStatus
// swagger:route GET /user-status Guardian getUserStatus

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// swagger:route GET /security-status Guardian getSecurityStatus
// Returns the security status.
// swagger:route GET /user-status Guardian getSecurityStatus
// Returns the security status of the user.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Returns the security status of the user.
// Returns the status of the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


facade := mockFacade.GuardianFacadeStub{
GetSecurityStatusCalled: func(request requests.UserStatusRequest) (*requests.UserStatusResponse, error) {
GetSecurityStatusCalled: func(userAddress string) (*requests.UserStatusResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this as well to GetUserStatusCalled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

if trials < maxFailures && expTime != core.NoExpiryValue {
trials, err := strconv.ParseInt(dbVal, 10, 64)
if err != nil {
log.Debug("error when returning security status", "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Debug("error when returning security status", "err", err)
log.Debug("error when converting security status", "err", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// GetSecurityStatus gets the user's security status
func (resolver *serviceResolver) GetSecurityStatus(request requests.UserStatusRequest) (*requests.UserStatusResponse, error) {
status, err := resolver.verifyUserReturningSecurityStatus(request.UserAddr)
// GetUserStatus gets the user's security status
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// GetUserStatus gets the user's security status
// GetUserStatus gets the user's status

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

SetSecurityModeNoExpireCalled func(userIp string, request requests.SecurityModeNoExpire) (*requests.OTPCodeVerifyData, error)
UnsetSecurityModeNoExpireCalled func(userIp string, request requests.SecurityModeNoExpire) (*requests.OTPCodeVerifyData, error)
GetSecurityStatusCalled func(request requests.UserStatusRequest) (*requests.UserStatusResponse, error)
GetSecurityStatusCalled func(userAddress string) (*requests.UserStatusResponse, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GetSecurityStatusCalled func(userAddress string) (*requests.UserStatusResponse, error)
GetUserStatusCalled func(userAddress string) (*requests.UserStatusResponse, error)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to also generate swagger files based on these changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@danielradu10 danielradu10 changed the base branch from main to rc/barnard June 30, 2025 10:48
Comment on lines 210 to 229




















Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

remove these empty lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

@sstanculeanu sstanculeanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observations after testing:

  • swagger not working, could not add parameters on the request

}
},
"userStatusResponse": {
"description": "The status of the operation",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status of which operation?

this should be the address/user status on the TCS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

const NoExpiryValue = -1

// Status represents the status of the security mode
type Status int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too generic, especially when used for the security mode

maybe EnhancedSecurityModeStatus

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed


// UserStatusResponse is the JSON response for the user status interrogation
type UserStatusResponse struct {
SecurityStatus int `json:"status"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to SecurityModeStatus? or EnhancedSecurityModeStatus?

SecurityStatus = NotSet doesn't sound good, as the account has protection via regular 2FA

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

_, err = resolver.getUserInfo(addressBytes)
resolver.userCritSection.RUnlock(string(addressBytes))
if err != nil {
return -1, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this -1 still needed?

sstanculeanu
sstanculeanu previously approved these changes Jul 1, 2025
ssd04
ssd04 previously approved these changes Jul 1, 2025
Base automatically changed from rc/barnard to main July 17, 2025 14:32
@sstanculeanu sstanculeanu dismissed stale reviews from ssd04 and themself July 17, 2025 14:32

The base branch was changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants