package com.qmth.boot.test.tools.signature;

import com.qmth.boot.tools.signature.SignatureEntity;
import com.qmth.boot.tools.signature.SignatureType;
import org.junit.Assert;
import org.junit.Test;

public class SignatureTest {

    private static String method = "POST";

    private static String uri = "/api/auth/demo";

    private static String invoker = "invoker";

    private static String secret = "token";

    @Test
    public void test() {
        long timestamp = System.currentTimeMillis();
        System.out.println(timestamp);
        String signature = SignatureEntity.build(SignatureType.TOKEN, method, uri, timestamp, invoker, secret);
        System.out.println(signature);
        SignatureEntity entity = SignatureEntity.parse(signature, method, uri, timestamp);
        Assert.assertNotNull(entity);
        Assert.assertEquals(entity.getInvoker(), invoker);
        Assert.assertTrue(entity.validate(secret));
    }
}
