Skip to content

Accept comma separated macaroons#146

Open
gofeuer wants to merge 1 commit intolightninglabs:masterfrom
gofeuer:comma-separator
Open

Accept comma separated macaroons#146
gofeuer wants to merge 1 commit intolightninglabs:masterfrom
gofeuer:comma-separator

Conversation

@gofeuer
Copy link
Copy Markdown

@gofeuer gofeuer commented Aug 11, 2024

#143
This will allow Aperture to receive comma separated macaroons and not reject the request as an error.
If multiple macaroons are received, the first one is used and the others are ignored (for now)

@guggero guggero self-requested a review August 12, 2024 07:32
Copy link
Copy Markdown
Contributor

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Thanks for the feature!
I think the approach is good. Most of my comments are around code style. I know this isn't specified explicitly in this project, but we try to adhere to the same formatting rules in all our projects.

Comment thread l402/header.go
if err != nil {
return nil, lntypes.Preimage{}, fmt.Errorf("base64 "+
"decode of macaroon failed: %v", err)
// macBase64 might be multiple macaroons separated by commas,
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.

nit: comments should always be full sentences, including punctuation.

I also think this needs some more explanation that we're using macaroon.Slice below, which can actually decode multiple macaroons that are in one continuous blob of data.

Comment thread l402/header.go
macBase64 = strings.ReplaceAll(macBase64, ",", "")
macBytes, err = base64.StdEncoding.DecodeString(macBase64)
if err != nil {
return nil, lntypes.Preimage{},
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.

nit: please break the lines before 80 characters, while configuring your IDE to show the tabulator character as 8 spaces (most of the code in this block is now too long).

Comment thread l402/header.go
}
}
mac := &macaroon.Macaroon{}
// macBytes can contain multiple macaroons,
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.

nit: add empty line before comment. Also missing full stop.

Comment thread l402/header.go
return nil, lntypes.Preimage{}, fmt.Errorf("unable to "+
"unmarshal macaroon: %v", err)
return nil, lntypes.Preimage{},
fmt.Errorf("unable to unmarshal macaroon: %v", 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.

Why this formatting change here and below?

Comment thread l402/header.go
"not found")
var preimageHex string
var ok bool
for _, m := range mac {
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 if there are multiple macaroons, then all of them should have the caveat. Not just one of them. Otherwise IMO the whole idea of having multiple macaroons is weird.

Comment thread l402/header.go
if !ok {
return nil, lntypes.Preimage{}, errors.New("preimage caveat " +
"not found")
var preimageHex string
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.

nit: multiple var statements can be combined into one:

var (
    ...
)

Comment thread l402/header.go
break
}
}
if preimageHex == "" || !ok {
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.

We probably also want to make sure all macaroons reference the same preimage.

Comment thread auth/authenticator.go
return false
}

// TODO: Be able to accept multiple macaroons
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.

nit: add full stop to end of sentence. Here and in server_interceptor.go.

Comment thread l402/header.go
fmt.Errorf("hex decode of macaroon failed: %v", err)
}
mac := &macaroon.Macaroon{}
mac := make(macaroon.Slice, 0, 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.

I know there isn't a unit test now, but it would be really nice to add one so this could be tested.

@lightninglabs-deploy
Copy link
Copy Markdown
Collaborator

@gofeuer, remember to re-request review from reviewers when ready

@guggero
Copy link
Copy Markdown
Contributor

guggero commented Nov 8, 2024

!lightninglabs-deploy mute

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.

3 participants