github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/service/lockdown_test.go (about)

     1  package service
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/keybase/client/go/kbtest"
     8  	"github.com/keybase/client/go/libkb"
     9  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestLockdownAPI(t *testing.T) {
    14  	tc := libkb.SetupTest(t, "lockdown", 3)
    15  	defer tc.Cleanup()
    16  
    17  	_, err := kbtest.CreateAndSignupFakeUser("lmu", tc.G)
    18  	require.NoError(t, err)
    19  
    20  	handler := NewAccountHandler(nil, tc.G)
    21  	ctx := context.Background()
    22  	res, err := handler.GetLockdownMode(ctx, 0)
    23  	require.NoError(t, err)
    24  	require.False(t, res.Status)
    25  	require.Len(t, res.History, 0)
    26  
    27  	err = handler.SetLockdownMode(ctx, keybase1.SetLockdownModeArg{
    28  		Enabled: true,
    29  	})
    30  	require.NoError(t, err)
    31  
    32  	res, err = handler.GetLockdownMode(ctx, 0)
    33  	require.NoError(t, err)
    34  	require.True(t, res.Status)
    35  	require.Len(t, res.History, 1)
    36  
    37  	require.True(t, res.History[0].Status)
    38  }
    39  
    40  func TestLockdownReset(t *testing.T) {
    41  	// See if we can still reset in lockdown mode.
    42  	// We should be able to!
    43  	tc := libkb.SetupTest(t, "lockdown", 3)
    44  	defer tc.Cleanup()
    45  
    46  	user, err := kbtest.CreateAndSignupFakeUser("lmu", tc.G)
    47  	require.NoError(t, err)
    48  
    49  	handler := NewAccountHandler(nil, tc.G)
    50  	ctx := context.Background()
    51  
    52  	err = handler.SetLockdownMode(ctx, keybase1.SetLockdownModeArg{
    53  		Enabled: true,
    54  	})
    55  	require.NoError(t, err)
    56  
    57  	res, err := handler.GetLockdownMode(ctx, 0)
    58  	require.NoError(t, err)
    59  	require.True(t, res.Status)
    60  
    61  	err = handler.ResetAccount(ctx, keybase1.ResetAccountArg{
    62  		Passphrase: user.Passphrase,
    63  	})
    64  	require.NoError(t, err)
    65  }
    66  
    67  func TestLockdownLogin(t *testing.T) {
    68  	tc := libkb.SetupTest(t, "lockdown", 3)
    69  	defer tc.Cleanup()
    70  
    71  	user, err := kbtest.CreateAndSignupFakeUser("lmu", tc.G)
    72  	require.NoError(t, err)
    73  
    74  	handler := NewAccountHandler(nil, tc.G)
    75  	ctx := context.Background()
    76  
    77  	err = handler.SetLockdownMode(ctx, keybase1.SetLockdownModeArg{
    78  		Enabled: true,
    79  	})
    80  	require.NoError(t, err)
    81  
    82  	m := libkb.NewMetaContextForTest(tc)
    83  	_, err = tc.G.ActiveDevice.SyncSecretsForce(m)
    84  	require.NoError(t, err)
    85  
    86  	kbtest.Logout(tc)
    87  	err = user.Login(tc.G)
    88  	require.NoError(t, err)
    89  }
    90  
    91  func TestLockdownProvisionAndLogin(t *testing.T) {
    92  	tc := libkb.SetupTest(t, "lockdown", 3)
    93  	defer tc.Cleanup()
    94  
    95  	user, err := kbtest.CreateAndSignupFakeUserPaper("lmu", tc.G)
    96  	require.NoError(t, err)
    97  
    98  	handler := NewAccountHandler(nil, tc.G)
    99  	ctx := context.Background()
   100  
   101  	err = handler.SetLockdownMode(ctx, keybase1.SetLockdownModeArg{
   102  		Enabled: true,
   103  	})
   104  	require.NoError(t, err)
   105  
   106  	tc2 := libkb.SetupTest(t, "lockdown_second", 3)
   107  	defer tc2.Cleanup()
   108  	kbtest.ProvisionNewDeviceKex(&tc, &tc2, user, keybase1.DeviceTypeV2_DESKTOP)
   109  
   110  	kbtest.Logout(tc)
   111  
   112  	err = user.Login(tc.G)
   113  	require.NoError(t, err)
   114  }