Skip to content

Commit

Permalink
Stop publishing Macaroons in BouncyCastle build.
Browse files Browse the repository at this point in the history
* Since Macaroons test has an annoying bug which only occurs in "windows * non-bouncycastle" build sporadically.
* See #153
  • Loading branch information
joemphilips committed Apr 12, 2021
1 parent 4812785 commit 0aa8268
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
dotnet run --project tests/DotNetLightning.Core.Tests
- name: Run other tests
run: |
dotnet test
dotnet test --filter "FullyQualifiedName!~Macaroon" # see https://github.com/joemphilips/DotNetLightning/issues/153
build_with_fsharp_from_mono:
runs-on: ubuntu-20.04
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetLightning.Core/DotNetLightning.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<WarningLevel>3</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<Choose>
<When Condition="'$(Portability)'=='true'">
<PropertyGroup>
Expand All @@ -26,7 +26,7 @@
<ProjectReference Condition="'$(Portability)'!='true'" Include="..\NSec\Experimental\NSec.Experimental.csproj" PrivateAssets="all" />
<ProjectReference Include="..\ResultUtils\ResultUtils.fsproj" PrivateAssets="all" />
<ProjectReference Include="..\InternalBech32Encoder\InternalBech32Encoder.csproj" PrivateAssets="all" />
<ProjectReference Include="..\Macaroons\Macaroons.csproj" PrivateAssets="all" />
<ProjectReference Include="..\Macaroons\Macaroons.csproj" ExcludeAssets="all" />
<ProjectReference Include="..\AEZ\AEZ.csproj" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
Expand Down
21 changes: 9 additions & 12 deletions tests/DotNetLightning.Core.Tests/Generators/Generators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ type PrimitiveGenerators =

static member UInt256(): Arbitrary<uint256> =
Arb.fromGen(uint256Gen)

static member PubKey() = Arb.fromGen(pubKeyGen)

static member NodeId() = Arb.fromGen(NodeId <!> pubKeyGen)


type P2PMsgGenerators =
static member Init() : Arbitrary<InitMsg> =
Arb.fromGen(initGen)
Expand Down Expand Up @@ -97,15 +97,15 @@ type P2PMsgGenerators =

static member ChannelUpdate(): Arbitrary<ChannelUpdateMsg> =
Arb.fromGen channelUpdateGen

static member QueryShortChannelIds(): Arbitrary<QueryShortChannelIdsMsg> =
Arb.fromGen queryShortChannelIdsGen

static member ReplyShortChannelIds() =
Arb.fromGen(replyShortChannelIdsEndGen)

static member QueryChannelRange() = Arb.fromGen queryChannelRangeGen

static member ReplyChannelRange = Arb.fromGen replyChannelRangeGen
static member GossipTimestampFilter = Arb.fromGen gossipTimestampFilterGen
static member OnionPayload() = Arb.fromGen(onionPayloadGen)
Expand Down Expand Up @@ -142,8 +142,5 @@ type P2PMsgGenerators =
gossipTimestampFilterGen |> Gen.map(fun i -> i :> ILightningMsg)
]
|> Arb.fromGen


type PaymentGenerators =
static member MacaroonIdentifier: Arbitrary<MacaroonIdentifier> =
macaroonIdGen |> Arb.fromGen


6 changes: 4 additions & 2 deletions tests/DotNetLightning.Core.Tests/Generators/Payments.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open DotNetLightning.Payment.LSAT
open DotNetLightning.Utils.Primitives
open FsCheck
open PrimitiveGenerators

#if BouncyCastle

let private macaroonIdV1Gen =
(uint256Gen |> Gen.map(PaymentHash.PaymentHash), uint256Gen)
||> Gen.map2(fun p u -> { MacaroonIdentifierV0.PaymentHash = p
TokenId = u })
|> Gen.map(MacaroonIdentifier.V0)
|> Gen.map(MacaroonIdentifier.V0)
let private macaroonUnknownIdGen(knownVersions: uint16 seq) =
gen {
let! t =
Expand All @@ -26,3 +26,5 @@ let macaroonIdGen: Gen<MacaroonIdentifier> =
macaroonIdV1Gen
macaroonUnknownIdGen([0us])
]

#endif
25 changes: 14 additions & 11 deletions tests/DotNetLightning.Core.Tests/LSATTests.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module DotNetLightning.Tests.LSATTests

#if BouncyCastle
open System
open System.Linq
open Expecto
Expand Down Expand Up @@ -33,7 +34,7 @@ let lsatTests =
let r = Service.ParseMany ",,"
Expect.isError (Result.ToFSharpCoreResult r) "can not parse empty services"
()

testList "check macaroon verification works in LSAT compliant way" [
testCase "successful verification" <| fun _ ->
let secret = "My secret key"
Expand All @@ -46,7 +47,7 @@ let lsatTests =
let v = m.VerifyLSATCaveats(caveats, satisfiers, secret)
Expect.isTrue(v.Success) (sprintf "%A" v.Messages)
()

testCase "successful verification with unknown service name" <| fun _ ->
let secret = "My secret key"
let identifier = "my macaroon identifier"
Expand All @@ -58,7 +59,7 @@ let lsatTests =
satisfiers.Add(ServiceSatisfier("my-service-name") :> ISatisfier)
let v = m.VerifyLSATCaveats(caveats, satisfiers, secret)
Expect.isTrue(v.Success) (sprintf "%A" v.Messages)

testCase "successful verification with capabilities satisfier" <| fun _ ->
let secret = "My secret key"
let identifier = "my macaroon identifier"
Expand All @@ -71,7 +72,7 @@ let lsatTests =
satisfiers.Add(CapabilitiesSatisfier("my-service-name", "read") :> ISatisfier)
let v = m.VerifyLSATCaveats(caveats, satisfiers, secret)
Expect.isTrue(v.Success) (sprintf "%A" v.Messages)

testCase "verification succeeds when caveats includes required capabilities" <| fun _ ->
let secret = "My secret key"
let identifier = "my macaroon identifier"
Expand All @@ -82,7 +83,7 @@ let lsatTests =
satisfiers.Add(CapabilitiesSatisfier("my-service-name", "read") :> ISatisfier)
let v = m.VerifyLSATCaveats(caveats, satisfiers, secret)
Expect.isTrue(v.Success) (sprintf "%A" v.Messages)

testCase "failure case: different secret" <| fun _ ->
let secret = "My secret key"
let identifier = "my macaroon identifier"
Expand All @@ -93,7 +94,7 @@ let lsatTests =
satisfiers.Add(ServiceSatisfier("my-service-name") :> ISatisfier)
let v = m.VerifyLSATCaveats(caveats, satisfiers, "wrong secret key")
Expect.isFalse(v.Success) ""

testCase "failure case: different service name" <| fun _ ->
let secret = "My secret key"
let identifier = "my macaroon identifier"
Expand All @@ -104,29 +105,31 @@ let lsatTests =
satisfiers.Add(ServiceSatisfier("my-service-name") :> ISatisfier)
let v = m.VerifyLSATCaveats(caveats, satisfiers, secret)
Expect.isFalse(v.Success) ""

testCase "failure case: verification fails if restriction gets loose then before" <| fun _ ->
let secret = "My secret key"
let identifier = "my macaroon identifier"
let m = Macaroon("http://my.awesome.service", secret, identifier)
let satisfiers = ResizeArray()
satisfiers.Add(ServiceSatisfier("my-service-name") :> ISatisfier)

let caveats = ResizeArray()
// latter caveats has more power here. which is invalid for lsat.
caveats.Add(Caveat("service=my-service-name:0"))
caveats.Add(Caveat("service=my-service-name:0,another-service-name:0"))

let v = m.VerifyLSATCaveats(caveats, satisfiers, secret)
Expect.isFalse(v.Success) ""

satisfiers.Add(CapabilitiesSatisfier("my-service-name", "read") :> ISatisfier)
let caveats = ResizeArray()
// latter caveats has more power here. which is invalid for lsat.
caveats.Add(Caveat("my-service-name_capabilities = read"))
caveats.Add(Caveat("my-service-name_capabilities = read,write"))
let v = m.VerifyLSATCaveats(caveats, satisfiers, secret)
Expect.isFalse(v.Success) ""

]
]

#endif
11 changes: 10 additions & 1 deletion tests/DotNetLightning.Core.Tests/PaymentPropertyTests.fs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
module DotNetLightning.Tests.PaymentPropertyTests

#if BouncyCastle

open DotNetLightning.Payment
open DotNetLightning.Payment.LSAT
open Expecto
open PaymentGenerators
open FsCheck
open Generators
open ResultUtils

type PaymentGenerators =
static member MacaroonIdentifier: Arbitrary<MacaroonIdentifier> =
macaroonIdGen |> Arb.fromGen

[<Tests>]
let lsatTests =
Expand All @@ -19,4 +26,6 @@ let lsatTests =
let i2 = MacaroonIdentifier.TryCreateFromBytes(i.ToBytes()) |> Result.deref
Expect.equal i i2 "failed to de/serialize macaroon id"
]


#endif

0 comments on commit 0aa8268

Please sign in to comment.