Search in sources :

Example 1 with Pin

use of okhttp3.CertificatePinner.Pin in project okhttp by square.

the class CertificatePinnerTest method successfulFindMatchingPinsIgnoresCase.

@Test
public void successfulFindMatchingPinsIgnoresCase() {
    CertificatePinner certificatePinner = new CertificatePinner.Builder().add("EXAMPLE.com", certA1Sha256Pin).add("*.MyExample.Com", certB1Sha256Pin).build();
    List<Pin> expectedPin1 = Arrays.asList(new Pin("EXAMPLE.com", certA1Sha256Pin));
    assertEquals(expectedPin1, certificatePinner.findMatchingPins("example.com"));
    List<Pin> expectedPin2 = Arrays.asList(new Pin("*.MyExample.Com", certB1Sha256Pin));
    assertEquals(expectedPin2, certificatePinner.findMatchingPins("a.myexample.com"));
}
Also used : Pin(okhttp3.CertificatePinner.Pin) Test(org.junit.Test)

Example 2 with Pin

use of okhttp3.CertificatePinner.Pin in project okhttp by square.

the class CertificatePinnerTest method successfulFindMatchingPinsForWildcardAndDirectCertificates.

@Test
public void successfulFindMatchingPinsForWildcardAndDirectCertificates() {
    CertificatePinner certificatePinner = new CertificatePinner.Builder().add("*.example.com", certA1Sha256Pin).add("a.example.com", certB1Sha256Pin).add("b.example.com", certC1Sha256Pin).build();
    List<Pin> expectedPins = Arrays.asList(new Pin("*.example.com", certA1Sha256Pin), new Pin("a.example.com", certB1Sha256Pin));
    assertEquals(expectedPins, certificatePinner.findMatchingPins("a.example.com"));
}
Also used : Pin(okhttp3.CertificatePinner.Pin) Test(org.junit.Test)

Example 3 with Pin

use of okhttp3.CertificatePinner.Pin in project okhttp by square.

the class CertificatePinnerTest method successfulFindMatchingPins.

@Test
public void successfulFindMatchingPins() {
    CertificatePinner certificatePinner = new CertificatePinner.Builder().add("first.com", certA1Sha256Pin, certB1Sha256Pin).add("second.com", certC1Sha256Pin).build();
    List<Pin> expectedPins = Arrays.asList(new Pin("first.com", certA1Sha256Pin), new Pin("first.com", certB1Sha256Pin));
    assertEquals(expectedPins, certificatePinner.findMatchingPins("first.com"));
}
Also used : Pin(okhttp3.CertificatePinner.Pin) Test(org.junit.Test)

Example 4 with Pin

use of okhttp3.CertificatePinner.Pin in project okhttp by square.

the class CertificatePinnerTest method successfulFindMatchingPinPunycode.

@Test
public void successfulFindMatchingPinPunycode() {
    CertificatePinner certificatePinner = new CertificatePinner.Builder().add("σkhttp.com", certA1Sha256Pin).build();
    List<Pin> expectedPin = Arrays.asList(new Pin("σkhttp.com", certA1Sha256Pin));
    assertEquals(expectedPin, certificatePinner.findMatchingPins("xn--khttp-fde.com"));
}
Also used : Pin(okhttp3.CertificatePinner.Pin) Test(org.junit.Test)

Example 5 with Pin

use of okhttp3.CertificatePinner.Pin in project retrofit by square.

the class RequestBuilderTest method formEncodedWithEncodedNameFieldParamMap.

@Test
public void formEncodedWithEncodedNameFieldParamMap() {
    class Example {

        //
        @FormUrlEncoded
        //
        @POST("/foo")
        Call<ResponseBody> method(@FieldMap(encoded = true) Map<String, Object> fieldMap) {
            return null;
        }
    }
    Map<String, Object> fieldMap = new LinkedHashMap<>();
    fieldMap.put("k%20it", "k%20at");
    fieldMap.put("pin%20g", "po%20ng");
    Request request = buildRequest(Example.class, fieldMap);
    assertBody(request.body(), "k%20it=k%20at&pin%20g=po%20ng");
}
Also used : FieldMap(retrofit2.http.FieldMap) Request(okhttp3.Request) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Pin (okhttp3.CertificatePinner.Pin)4 HeldCertificate (okhttp3.internal.tls.HeldCertificate)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Certificate (java.security.cert.Certificate)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 Request (okhttp3.Request)1 ResponseBody (okhttp3.ResponseBody)1 FieldMap (retrofit2.http.FieldMap)1 HeaderMap (retrofit2.http.HeaderMap)1 PartMap (retrofit2.http.PartMap)1 QueryMap (retrofit2.http.QueryMap)1