mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-30 22:12:25 -05:00 
			
		
		
		
	start refactoring return codes from fedi endpoints, remove some cruft
This commit is contained in:
		
					parent
					
						
							
								c6044d0142
							
						
					
				
			
			
				commit
				
					
						47051a26d6
					
				
			
		
					 28 changed files with 346 additions and 291 deletions
				
			
		|  | @ -30,24 +30,11 @@ import ( | |||
| 
 | ||||
| type commonAuth struct { | ||||
| 	handshakingURI *url.URL          // Set to requestingAcct's URI if we're currently handshaking them. | ||||
| 	requestingAcct *gtsmodel.Account // Remote account making request to this instance. | ||||
| 	receivingAcct  *gtsmodel.Account // Local account receiving the request. | ||||
| 	requester      *gtsmodel.Account // Remote account making request to this instance. | ||||
| 	receiver       *gtsmodel.Account // Local account receiving the request. | ||||
| } | ||||
| 
 | ||||
| func (p *Processor) authenticate(ctx context.Context, requestedUser string) (*commonAuth, gtserror.WithCode) { | ||||
| 	// First get the requested (receiving) LOCAL account with username from database. | ||||
| 	receiver, err := p.state.DB.GetAccountByUsernameDomain(ctx, requestedUser, "") | ||||
| 	if err != nil { | ||||
| 		if !errors.Is(err, db.ErrNoEntries) { | ||||
| 			// Real db error. | ||||
| 			err = gtserror.Newf("db error getting account %s: %w", requestedUser, err) | ||||
| 			return nil, gtserror.NewErrorInternalError(err) | ||||
| 		} | ||||
| 
 | ||||
| 		// Account just not found in the db. | ||||
| 		return nil, gtserror.NewErrorNotFound(err) | ||||
| 	} | ||||
| 
 | ||||
| 	// Ensure request signed, and use signature URI to | ||||
| 	// get requesting account, dereferencing if necessary. | ||||
| 	pubKeyAuth, errWithCode := p.federator.AuthenticateFederatedRequest(ctx, requestedUser) | ||||
|  | @ -55,31 +42,46 @@ func (p *Processor) authenticate(ctx context.Context, requestedUser string) (*co | |||
| 		return nil, errWithCode | ||||
| 	} | ||||
| 
 | ||||
| 	// Get the requested local account | ||||
| 	// with given username from database. | ||||
| 	receiver, err := p.state.DB.GetAccountByUsernameDomain(ctx, requestedUser, "") | ||||
| 	if err != nil && !errors.Is(err, db.ErrNoEntries) { | ||||
| 		err = gtserror.Newf("db error getting account %s: %w", requestedUser, err) | ||||
| 		return nil, gtserror.NewErrorInternalError(err) | ||||
| 	} | ||||
| 
 | ||||
| 	if receiver == nil { | ||||
| 		err := gtserror.Newf("account %s not found in the db", requestedUser) | ||||
| 		return nil, gtserror.NewErrorNotFound(err) | ||||
| 	} | ||||
| 
 | ||||
| 	if pubKeyAuth.Handshaking { | ||||
| 		// We're still handshaking so we | ||||
| 		// don't know the requester yet. | ||||
| 		return &commonAuth{ | ||||
| 			handshakingURI: pubKeyAuth.OwnerURI, | ||||
| 			receivingAcct:  receiver, | ||||
| 			receiver:       receiver, | ||||
| 		}, nil | ||||
| 	} | ||||
| 
 | ||||
| 	// Get requester from auth. | ||||
| 	requester := pubKeyAuth.Owner | ||||
| 
 | ||||
| 	// Ensure block does not exist between receiver and requester. | ||||
| 	blocked, err := p.state.DB.IsEitherBlocked(ctx, receiver.ID, requester.ID) | ||||
| 	// Ensure receiver does not block requester. | ||||
| 	blocked, err := p.state.DB.IsBlocked(ctx, receiver.ID, requester.ID) | ||||
| 	if err != nil { | ||||
| 		err := gtserror.Newf("error checking block: %w", err) | ||||
| 		err := gtserror.Newf("db error checking block: %w", err) | ||||
| 		return nil, gtserror.NewErrorInternalError(err) | ||||
| 	} else if blocked { | ||||
| 		const text = "block exists between accounts" | ||||
| 	} | ||||
| 
 | ||||
| 	if blocked { | ||||
| 		var text = requestedUser + " blocks " + requester.Username | ||||
| 		return nil, gtserror.NewErrorForbidden(errors.New(text)) | ||||
| 	} | ||||
| 
 | ||||
| 	return &commonAuth{ | ||||
| 		requestingAcct: requester, | ||||
| 		receivingAcct:  receiver, | ||||
| 		requester: requester, | ||||
| 		receiver:  receiver, | ||||
| 	}, nil | ||||
| } | ||||
| 
 | ||||
|  | @ -120,7 +122,7 @@ func (p *Processor) validateIntReqRequest( | |||
| 
 | ||||
| 	// Ensure interaction request was accepted | ||||
| 	// by the account in the request path. | ||||
| 	if req.TargetAccountID != auth.receivingAcct.ID { | ||||
| 	if req.TargetAccountID != auth.receiver.ID { | ||||
| 		text := fmt.Sprintf( | ||||
| 			"account %s is not targeted by interaction request %s and therefore can't accept it", | ||||
| 			requestedUser, intReqID, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue