@@ -474,6 +474,10 @@ func TestFirewallDBMigration(t *testing.T) {
474474 name : "action with no session or account" ,
475475 populateDB : actionNoSessionOrAccount ,
476476 },
477+ {
478+ name : "action with empty RPCParamsJson" ,
479+ populateDB : actionEmptyRPCParamsJson ,
480+ },
477481 {
478482 name : "action with session but no account" ,
479483 populateDB : actionWithSessionNoAccount ,
@@ -1268,6 +1272,32 @@ func actionNoSessionOrAccount(t *testing.T, ctx context.Context,
12681272 }
12691273}
12701274
1275+ // actionEmptyRPCParamsJson adds an action which has no RPCParamsJson set.
1276+ func actionEmptyRPCParamsJson (t * testing.T , ctx context.Context ,
1277+ boltDB * BoltDB , _ session.Store , _ accounts.Store ,
1278+ rStore * rootKeyMockStore ) * expectedResult {
1279+
1280+ // As the action is not linked to any session, we add a random root
1281+ // key which we use as the macaroon identifier for the action.
1282+ // This simulates how similar actions would have been created in
1283+ // production.
1284+ rootKey := rStore .addRandomRootKey ()
1285+
1286+ actionReq := testActionReq
1287+ actionReq .MacaroonRootKeyID = fn .Some (rootKey )
1288+ actionReq .SessionID = fn .None [session.ID ]()
1289+ actionReq .AccountID = fn .None [accounts.AccountID ]()
1290+ actionReq .RPCParamsJson = []byte {}
1291+
1292+ action := addAction (t , ctx , boltDB , & actionReq )
1293+
1294+ return & expectedResult {
1295+ kvEntries : []* kvEntry {},
1296+ privPairs : make (privacyPairs ),
1297+ actions : []* Action {action },
1298+ }
1299+ }
1300+
12711301// actionWithSessionNoAccount adds an action which is linked a session but no
12721302// account.
12731303func actionWithSessionNoAccount (t * testing.T , ctx context.Context ,
@@ -1967,6 +1997,13 @@ func addAction(t *testing.T, ctx context.Context, boltDB *BoltDB,
19671997 action .AccountID = actionReq .AccountID
19681998 action .MacaroonRootKeyID = actionReq .MacaroonRootKeyID
19691999
2000+ // In case the actionReq's RPCParamsJson wasn't set, we need to set the
2001+ // expected action's RPCParamsJson to nil as that's how such
2002+ // RPCParamsJson are represented in
2003+ if len (actionReq .RPCParamsJson ) == 0 {
2004+ action .RPCParamsJson = nil
2005+ }
2006+
19702007 return action
19712008}
19722009
@@ -2155,6 +2192,11 @@ func randomBytes(n int) []byte {
21552192// Keys are random strings like "key1", "key2"...
21562193// Values are random ints, floats, or strings.
21572194func randomJSON (n int ) (string , error ) {
2195+ // When 0 pairs are requested, we can return immediately.
2196+ if n <= 0 {
2197+ return "" , nil
2198+ }
2199+
21582200 obj := make (map [string ]any , n )
21592201 for i := 0 ; i < n ; i ++ {
21602202 key := fmt .Sprintf ("key%d" , i + 1 )
0 commit comments