github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/kbpackets_test.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package libkb
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestBadMsgpack(t *testing.T) {
    13  	info, err := DecodeArmoredNaclEncryptionInfoPacket(`
    14  g6Rib2R5hqhkZXRhY2hlw6loYXNoX3R5cGUKo2tlecQjASBz6XLVJ/u0KKVpvp9QlcNvIopFsusm
    15  wjFFHVUYo3ykIwqncGF5bG9hZMUD7XsiYm9keSI6eyJkZXZpY2UiOnsiaWQiOiIwNTc4NDNjMjAy
    16  NTE5MjZhY2MwZDVkYjMxMjY5NzkxOCIsImtpZCI6IjAxMjEzNzlkNTM3MGFlYjRlOWY3YWE0YjUy
    17  NzBmNWU0ODgwODVhNjQ3ZTBkYjI0NzdlZGQzZjNjNTBlM2QxNGY0MDRmMGEiLCJzdGF0dXMiOjF9
    18  LCJrZXkiOnsiZWxkZXN0X2tpZCI6IjAxMjBjN2E5NGM0NDI3NjA5NWU3MzY1ZjQ5YjY3YWU2OGY3
    19  YmNiYzgwNWM1ODI3OTdmNjkwYjY3YjA4ZjA1ZWRmZTFiMGEiLCJob3N0Ijoia2V5YmFzZS5pbyIs
    20  ImtpZCI6IjAxMjA3M2U5NzJkNTI3ZmJiNDI4YTU2OWJlOWY1MDk1YzM2ZjIyOGE0NWIyZWIyNmMy
    21  MzE0NTFkNTUxOGEzN2NhNDIzMGEiLCJ1aWQiOiJhMDkxNTUyMTA1MzJkOTYwODFjNGEzYTk5YzY0
    22  ODQxOSIsInVzZXJuYW1lIjoibHdwcF80MjJhYjc5ODQ3In0sInN1YmtleSI6eyJraWQiOiIwMTIx
    23  Mzc5ZDUzNzBhZWI0ZTlmN2FhNGI1MjcwZjVlNDg4MDg1YTY0N2UwZGIyNDc3ZWRkM2YzYzUwZTNk
    24  MTRmNDA0ZjBhIiwicGFyZW50X2tpZCI6IjAxMjA3M2U5NzJkNTI3ZmJiNDI4YTU2OWJlOWY1MDk1
    25  YzM2ZjIyOGE0NWIyZWIyNmMyMzE0NTFkNTUxOGEzN2NhNDIzMGEifSwidHlwZSI6InN1YmtleSIs
    26  InZlcnNpb24iOjF9LCJjbGllbnQiOnsibmFtZSI6ImtleWJhc2UuaW8gZ28gY2xpZW50IiwidmVy
    27  c2lvbiI6IjEuMC4wIn0sImN0aW1lIjoxNDQzNDY1OTQzLCJleHBpcmVfaW4iOjUwNDU3NjAwMCwi
    28  bWVya2xlX3Jvb3QiOnsiY3RpbWUiOjE0NDM0NjU5NDMsImhhc2giOiI4ZWIzM2IwNmMxZTAyMjFh
    29  Y2JhY2UzMDZkMjNlYTFkOTIyYmFhYWNjNmFiYmQyN2MzOWNmNjNiY2MyNjczNGVmNDg1MGNmODc2
    30  YWZlNjkxNTc4NDk4NDEzZTJlOTc0M2I3OWI5N2JlMTYxZWMwOGRiNGNmMjk2YmQ1ZTk4YjVmZSIs
    31  InNlcW5vIjo1NjN9LCJwcmV2IjoiZWUwMDc4NTgyNDZhZGY4ODU1OTc2NmYxNjRkMGIxOTUzMDMy
    32  MDljYmQ4MmFmYTdmYzZkZWQxOGI0OWI3YjZiMiIsInNlcW5vIjo0LCJ0YWciOiJzaWduYXR1cmUi
    33  faNzaWfEQG3uIt5g6X6NRAjnHdF1NSRO5UYJD1B0Ku1ixBIeS2zuSAGR0pts2Lbl+Cz3BGvu9isq
    34  7MHrgCa2r1PEo4C/4ACoc2lnX3R5cGUgo3RhZ80CAqd2ZXJzaW9uAQ==
    35  `)
    36  	require.Error(t, err, "Malformed msgpack should fail to decode, but decoded to: %#v", info)
    37  }
    38  
    39  // This is a regression test for
    40  // https://github.com/ugorji/go/issues/237 .
    41  func TestMsgpackReencodeNilHash(t *testing.T) {
    42  	// This message has a nil hash.
    43  	info, err := DecodeArmoredNaclEncryptionInfoPacket(`
    44  hKRib2R5hapjaXBoZXJ0ZXh0wKhlbmNfdHlwZQClbm9uY2XArHJlY2VpdmVyX2tlecCqc2VuZGVy
    45  X2tlecCkaGFzaIKkdHlwZQildmFsdWXEIJZSZH19AzYud7qy9x3yx1hN2MooqnhjsytUSqTK+VMZ
    46  o3RhZ80CA6d2ZXJzaW9uAQ==
    47  `)
    48  	// In particular, shouldn't return a FishyMsgpackError.
    49  	require.NoError(t, err, "info=%+v", info)
    50  }