github.com/anycable/anycable-go@v1.5.1/features/standalone.testfile (about)

     1  launch :anycable,
     2    "./dist/anycable-go --secret=s3Krit --norpc"
     3  
     4  wait_tcp 8080
     5  
     6  payload = {ext: {}.to_json, exp: (Time.now.to_i + 60)}
     7  
     8  token = ::JWT.encode(payload, "s3Krit", "HS256")
     9  
    10  verifier = ActiveSupport::MessageVerifier.new("s3Krit", digest: "SHA256", serializer: JSON)
    11  signed_stream_name = verifier.generate("chat/2023")
    12  
    13  # Authenticated client + subscription
    14  scenario = [
    15    {
    16      client: {
    17        protocol: "action_cable",
    18        name: "turbo",
    19        connection_options: {
    20          query: {
    21            jid: token
    22          }
    23        },
    24        actions: [
    25          {
    26            subscribe: {
    27              channel: "$pubsub",
    28              params: {
    29                signed_stream_name: signed_stream_name
    30              }
    31            }
    32          },
    33        ]
    34      }
    35    }
    36  ]
    37  
    38  TEST_COMMAND = <<~CMD
    39    bundle exec wsdirector ws://localhost:8080/cable -i #{scenario.to_json}
    40  CMD
    41  
    42  run :wsdirector, TEST_COMMAND
    43  
    44  result = stdout(:wsdirector)
    45  
    46  unless result.include?("1 clients, 0 failures")
    47    fail "Unexpected scenario result:\n#{result}"
    48  end
    49  
    50  # Unauthenticated client
    51  scenario = [
    52    {
    53      receive: {
    54        data: {
    55          type: "disconnect",
    56          reason: "unauthorized",
    57          reconnect: false
    58        }
    59      }
    60    }
    61  ]
    62  
    63  TEST_COMMAND = <<~CMD
    64    bundle exec wsdirector ws://localhost:8080/cable -i #{scenario.to_json}
    65  CMD
    66  
    67  run :wsdirector, TEST_COMMAND
    68  
    69  result = stdout(:wsdirector)
    70  
    71  unless result.include?("1 clients, 0 failures")
    72    fail "Unexpected scenario result:\n#{result}"
    73  end