-
Notifications
You must be signed in to change notification settings - Fork 45
Stateless remote mode: Adds passing in macaroon and tls data, and a CheckMacaroonPermissions RPC #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
guggero
merged 6 commits into
lightninglabs:lnd-13-0
from
orbitalturtle:custom-macaroon-hex
Sep 21, 2021
Merged
Stateless remote mode: Adds passing in macaroon and tls data, and a CheckMacaroonPermissions RPC #51
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc17a3b
Add CustomMacaroonHex as a config option
orbitalturtle 692d8ab
Test that new CustomMacaroonHex option works properly
orbitalturtle 3a5ec2d
Allow passing in tls certificate as data
orbitalturtle f374c88
Add support for passing in macaroons/tls cert as data to basic client
orbitalturtle 577f819
Add CheckMacaroonPermissions command to client
orbitalturtle bd95f28
Update dependencies with required change to lnd
orbitalturtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package lndclient | ||
|
||
import ( | ||
"encoding/hex" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// Tests that NewBasicConn works correctly when macaroon and TLS certificate | ||
// data are passed in directly instead of being supplied as file paths. | ||
func TestParseTLSAndMacaroon(t *testing.T) { | ||
|
||
tlsData := `-----BEGIN CERTIFICATE----- | ||
MIIDhzCCAm+gAwIBAgI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7Eb9j3128diIwljf9JXNT | ||
I/LThs8Nl5RSiMOuGer0e934vLlZlrEEI4rWs3DKK56WjrMeVf5dhvYK44usNwUh | ||
vKgMVFsUeyLLTN0EuZjGoFdi3lfLQo3vRwLD6h/EDa5uWK14pZXDQ30+fT2RjuVD | ||
XhkpT5dliEGFLNe6OOgeWTU1JpEXfCud/GImtNMHQi4EDWQfvWuCNGhOoQ== | ||
-----END CERTIFICATE-----` | ||
|
||
macData := "0201047465737402067788991234560000062052d26ed139ea5af8" + | ||
"3e675500c4ccb2471f62191b745bab820f129e5588a255d2" | ||
|
||
// Make sure it works when data is passed in. | ||
_, _, err := parseTLSAndMacaroon( | ||
"", "", tlsData, macData, "mainnet", false, false, | ||
MacFilename(""), | ||
) | ||
require.NoError(t, err) | ||
|
||
// Now let's write the data to a file to make sure parseTLSAndMacaroon | ||
// parses that properly as well. | ||
tempDirPath, err := ioutil.TempDir("", ".testCreds") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tempDirPath) | ||
|
||
certPath := tempDirPath + "/tls.cert" | ||
tlsPEMBytes := []byte(tlsData) | ||
|
||
err = ioutil.WriteFile(certPath, tlsPEMBytes, 0644) | ||
require.NoError(t, err) | ||
|
||
macPath := tempDirPath + "/test.macaroon" | ||
macBytes, err := hex.DecodeString(macData) | ||
require.NoError(t, err) | ||
|
||
err = ioutil.WriteFile(macPath, macBytes, 0644) | ||
require.NoError(t, err) | ||
|
||
_, _, err = parseTLSAndMacaroon( | ||
certPath, macPath, "", "", "mainnet", false, false, | ||
MacFilename(""), | ||
) | ||
require.NoError(t, err) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive by comment, but rather than breaking the interface here, this should've just used a
BasicClientOption
as that's how the API is intended to evolve.IMO we should likely follow this path, as otherwise updating will break every user of
NewBasicConn
as is.