md5

package
Version: v6.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

md5

Provides a integrity check transfer filter

Usage

import "github.com/henrylee2cn/teleport/v6/xfer/md5"

Test
package md5_test

import (
	"testing"
	"time"

	tp "github.com/henrylee2cn/teleport/v6"
	"github.com/henrylee2cn/teleport/v6/xfer"
	"github.com/henrylee2cn/teleport/v6/xfer/md5"
)

func TestSeparate(t *testing.T) {
	// Register filter(custom)
	md5.Reg('m', "md5")
	md5Check, _ := xfer.Get('m')
	input := []byte("md5")
	b, err := md5Check.OnPack(input)
	if err != nil {
		t.Fatalf("Onpack: %v", err)
	}

	_, err = md5Check.OnUnpack(b)
	if err != nil {
		t.Fatalf("Md5 check failed: %v", err)
	}

	// Tamper with data
	b = append(b, "viruses"...)
	_, err = md5Check.OnUnpack(b)
	if err == nil {
		t.Fatal("Md5 check failed:")
	}
}

func TestCombined(t *testing.T) {
	// Register filter(custom)
	md5.Reg('m', "md5")
	// Server
	srv := tp.NewPeer(tp.PeerConfig{ListenPort: 9090})
	srv.RouteCall(new(Home))
	go srv.ListenAndServe()
	time.Sleep(1e9)

	// Client
	cli := tp.NewPeer(tp.PeerConfig{})
	sess, stat := cli.Dial(":9090")
	if !stat.OK() {
		t.Fatal(stat)
	}
	var result interface{}
	stat = sess.Call("/home/test",
		map[string]interface{}{
			"bytes": "test bytes",
		},
		&result,
		// Use custom filter
		tp.WithXferPipe('m'),
	).Status()
	if !stat.OK() {
		t.Error(stat)
	}
	t.Logf("result:%v", result)
}

type Home struct {
	tp.CallCtx
}

func (h *Home) Test(arg *map[string]interface{}) (map[string]interface{}, *tp.Status) {
	return map[string]interface{}{
		"result": "your request is:" + (*arg)["bytes"].(string),
	}, nil
}

test command:

# Separate test
go test -v -run=TestSeparate
# Combined with teleport test
go test -v -run=TestCombined

Documentation

Overview

Package md5 provides a integrity check transfer filter

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reg

func Reg(id byte, name string)

Reg registers a md5 checker filter for transfer.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL