Skip to content

endpoint for status of the user - #162

Open
danielradu10 wants to merge 22 commits into
mainfrom
user-status
Open

endpoint for status of the user#162
danielradu10 wants to merge 22 commits into
mainfrom
user-status

Conversation

@danielradu10

Copy link
Copy Markdown
Contributor

No description provided.

@sstanculeanu
sstanculeanu self-requested a review May 5, 2025 08:24
Comment thread api/groups/common_test.go Outdated
{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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed it

Comment thread api/groups/guardianGroup.go Outdated
logUserStatusRequest(userIp, userAgent, &request, debugErr)
}()

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread cmd/multi-factor-auth/config/api.toml Outdated
{ 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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment thread core/constants.go Outdated
// NoExpiryValue is the returned value for a persistent key expiry time
const NoExpiryValue = -1

type Status int

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

Comment thread core/requests/types.go Outdated
UserAddr string `json:"user"`
}

// UserStatusResponse - is the JSON response for the user status interrogation

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread resolver/serviceResolver.go Outdated
return resolver.verifyCodesReturningGuardian(userAddress, txs[0].GuardianAddr, userIp, code, secondCode)
}

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed it

Comment thread resolver/serviceResolver.go Outdated
func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) {
userAddress, err := sdkData.NewAddressFromBech32String(userAddr)
if err != nil {
return 0, err

Copy link
Copy Markdown
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
Copy Markdown
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 thread resolver/serviceResolver.go Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread testscommon/rateLimiterStub.go Outdated
if r.GetSecurityStatusCalled != nil {
return r.GetSecurityStatusCalled(key)
}
return -1

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread testscommon/rateLimiterMock.go Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread api/groups/guardianGroup.go Outdated
signMultipleTransactionsPath = "/sign-multiple-transactions"
setSecurityModeNoExpirePath = "/set-security-mode"
unsetSecurityModeNoExpirePath = "/unset-security-mode"
getSecurityStatus = "/security-status"

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed

Comment thread core/constants.go Outdated
Comment on lines +34 to +39
type Status int

const (
NotSet Status = iota
ManualSet
AutomaticallySet

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

Comment thread go.sum

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment thread handlers/secureOtp/secureOtpHandler.go Outdated
return totp.rateLimiter.UnsetSecurityModeNoExpire(key)
}

// GetSecurityStatus - returns the status of the security mode

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment thread resolver/serviceResolver.go Outdated
_, err = resolver.getUserInfo(addressBytes)
resolver.userCritSection.RUnlock(string(addressBytes))
if err != nil {
return -1, err

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread cmd/multi-factor-auth/swagger/data.go Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread cmd/multi-factor-auth/swagger/data.go Outdated
// 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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread api/groups/guardianGroup_test.go Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed

Comment thread redis/redisLimiter.go Outdated
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread resolver/serviceResolver.go Outdated
// 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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread testscommon/serviceResolverStub.go Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@sstanculeanu sstanculeanu left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread core/constants.go Outdated
const NoExpiryValue = -1

// Status represents the status of the security mode
type Status int

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed

Comment thread core/requests/types.go Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread resolver/serviceResolver.go Outdated
_, err = resolver.getUserInfo(addressBytes)
resolver.userCritSection.RUnlock(string(addressBytes))
if err != nil {
return -1, err

Copy link
Copy Markdown
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.

4 participants