github.com/livekit/protocol@v1.16.1-0.20240517185851-47e4c6bba773/egress/redact_test.go (about)

     1  package egress
     2  
     3  import (
     4  	"testing"
     5  
     6  	"google.golang.org/protobuf/proto"
     7  
     8  	"github.com/livekit/protocol/livekit"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  var (
    13  	file = &livekit.EncodedFileOutput{
    14  		Output: &livekit.EncodedFileOutput_S3{
    15  			S3: &livekit.S3Upload{
    16  				AccessKey: "ACCESS_KEY",
    17  				Secret:    "LONG_SECRET_STRING",
    18  			},
    19  		},
    20  	}
    21  
    22  	image = &livekit.ImageOutput{
    23  		Output: &livekit.ImageOutput_AliOSS{
    24  			AliOSS: &livekit.AliOSSUpload{
    25  				AccessKey: "ACCESS_KEY",
    26  				Secret:    "LONG_SECRET_STRING",
    27  			},
    28  		},
    29  	}
    30  
    31  	segments = &livekit.SegmentedFileOutput{
    32  		Output: &livekit.SegmentedFileOutput_Gcp{
    33  			Gcp: &livekit.GCPUpload{
    34  				Credentials: "CREDENTIALS",
    35  			},
    36  		},
    37  	}
    38  
    39  	directFile = &livekit.DirectFileOutput{
    40  		Output: &livekit.DirectFileOutput_Azure{
    41  			Azure: &livekit.AzureBlobUpload{
    42  				AccountName: "ACCOUNT_NAME",
    43  				AccountKey:  "ACCOUNT_KEY",
    44  			},
    45  		},
    46  	}
    47  )
    48  
    49  func TestRedactUpload(t *testing.T) {
    50  	cl := proto.Clone(file)
    51  	RedactUpload(cl.(UploadRequest))
    52  
    53  	require.Equal(t, "{access_key}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_S3).S3.AccessKey)
    54  	require.Equal(t, "{secret}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_S3).S3.Secret)
    55  
    56  	cl = proto.Clone(image)
    57  	RedactUpload(cl.(UploadRequest))
    58  
    59  	require.Equal(t, "{access_key}", cl.(*livekit.ImageOutput).Output.(*livekit.ImageOutput_AliOSS).AliOSS.AccessKey)
    60  	require.Equal(t, "{secret}", cl.(*livekit.ImageOutput).Output.(*livekit.ImageOutput_AliOSS).AliOSS.Secret)
    61  
    62  	cl = proto.Clone(segments)
    63  	RedactUpload(cl.(UploadRequest))
    64  
    65  	require.Equal(t, "{credentials}", cl.(*livekit.SegmentedFileOutput).Output.(*livekit.SegmentedFileOutput_Gcp).Gcp.Credentials)
    66  
    67  	cl = proto.Clone(directFile)
    68  	RedactUpload(cl.(UploadRequest))
    69  
    70  	require.Equal(t, "{account_name}", cl.(*livekit.DirectFileOutput).Output.(*livekit.DirectFileOutput_Azure).Azure.AccountName)
    71  	require.Equal(t, "{account_key}", cl.(*livekit.DirectFileOutput).Output.(*livekit.DirectFileOutput_Azure).Azure.AccountKey)
    72  }
    73  
    74  func TestRedactStreamOutput(t *testing.T) {
    75  	so := &livekit.StreamOutput{
    76  		Urls: []string{
    77  			"rtmps://foo.bar.com/app/secret_stream_key",
    78  		},
    79  	}
    80  
    81  	RedactStreamKeys(so)
    82  	require.Equal(t, "rtmps://foo.bar.com/app/{sec...key}", so.Urls[0])
    83  }
    84  
    85  func TestRedactEncodedOutputs(t *testing.T) {
    86  	trackComposite := &livekit.TrackCompositeEgressRequest{
    87  		FileOutputs: []*livekit.EncodedFileOutput{
    88  			file,
    89  		},
    90  	}
    91  
    92  	cl := proto.Clone(trackComposite)
    93  	RedactEncodedOutputs(cl.(EncodedOutput))
    94  
    95  	require.Equal(t, "{access_key}", cl.(*livekit.TrackCompositeEgressRequest).FileOutputs[0].Output.(*livekit.EncodedFileOutput_S3).S3.AccessKey)
    96  	require.Equal(t, "{secret}", cl.(*livekit.TrackCompositeEgressRequest).FileOutputs[0].Output.(*livekit.EncodedFileOutput_S3).S3.Secret)
    97  
    98  	roomComposite := &livekit.RoomCompositeEgressRequest{
    99  		ImageOutputs: []*livekit.ImageOutput{
   100  			image,
   101  		},
   102  	}
   103  
   104  	cl = proto.Clone(roomComposite)
   105  	RedactEncodedOutputs(cl.(EncodedOutput))
   106  
   107  	require.Equal(t, "{access_key}", cl.(*livekit.RoomCompositeEgressRequest).ImageOutputs[0].Output.(*livekit.ImageOutput_AliOSS).AliOSS.AccessKey)
   108  	require.Equal(t, "{secret}", cl.(*livekit.RoomCompositeEgressRequest).ImageOutputs[0].Output.(*livekit.ImageOutput_AliOSS).AliOSS.Secret)
   109  
   110  	participant := &livekit.ParticipantEgressRequest{
   111  		SegmentOutputs: []*livekit.SegmentedFileOutput{
   112  			segments,
   113  		},
   114  	}
   115  
   116  	cl = proto.Clone(participant)
   117  	RedactEncodedOutputs(cl.(EncodedOutput))
   118  
   119  	require.Equal(t, "{credentials}", cl.(*livekit.ParticipantEgressRequest).SegmentOutputs[0].Output.(*livekit.SegmentedFileOutput_Gcp).Gcp.Credentials)
   120  }
   121  
   122  func TestRedactDirectOutput(t *testing.T) {
   123  	track := &livekit.TrackEgressRequest{
   124  		Output: &livekit.TrackEgressRequest_File{
   125  			File: &livekit.DirectFileOutput{
   126  				Output: &livekit.DirectFileOutput_S3{
   127  					S3: &livekit.S3Upload{
   128  						AccessKey: "ACCESS_KEY",
   129  						Secret:    "SECRET",
   130  					},
   131  				},
   132  			},
   133  		},
   134  	}
   135  
   136  	RedactDirectOutputs(track)
   137  	require.Equal(t, "{access_key}", track.Output.(*livekit.TrackEgressRequest_File).File.Output.(*livekit.DirectFileOutput_S3).S3.AccessKey)
   138  	require.Equal(t, "{secret}", track.Output.(*livekit.TrackEgressRequest_File).File.Output.(*livekit.DirectFileOutput_S3).S3.Secret)
   139  }