From 29b79db998912e276531ff836420636bc8130270 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 6 Apr 2021 16:45:06 +0300 Subject: [PATCH] oracle: we only work with https, forget http --- pkg/core/oracle_test.go | 44 +++++++++++++++++----------------- pkg/services/oracle/request.go | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pkg/core/oracle_test.go b/pkg/core/oracle_test.go index 81fa264a5..fb2bbb0bf 100644 --- a/pkg/core/oracle_test.go +++ b/pkg/core/oracle_test.go @@ -133,19 +133,19 @@ func TestOracle(t *testing.T) { cs := getOracleContractState(bc.contracts.Oracle.Hash, bc.contracts.Std.Hash) require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs)) - putOracleRequest(t, cs.Hash, bc, "http://get.1234", nil, "handle", []byte{}, 10_000_000) - putOracleRequest(t, cs.Hash, bc, "http://get.1234", nil, "handle", []byte{}, 10_000_000) - putOracleRequest(t, cs.Hash, bc, "http://get.timeout", nil, "handle", []byte{}, 10_000_000) - putOracleRequest(t, cs.Hash, bc, "http://get.notfound", nil, "handle", []byte{}, 10_000_000) - putOracleRequest(t, cs.Hash, bc, "http://get.forbidden", nil, "handle", []byte{}, 10_000_000) - putOracleRequest(t, cs.Hash, bc, "http://private.url", nil, "handle", []byte{}, 10_000_000) - putOracleRequest(t, cs.Hash, bc, "http://get.big", nil, "handle", []byte{}, 10_000_000) - putOracleRequest(t, cs.Hash, bc, "http://get.maxallowed", nil, "handle", []byte{}, 10_000_000) - putOracleRequest(t, cs.Hash, bc, "http://get.maxallowed", nil, "handle", []byte{}, 100_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.1234", nil, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.1234", nil, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.timeout", nil, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.notfound", nil, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.forbidden", nil, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://private.url", nil, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.big", nil, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.maxallowed", nil, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.maxallowed", nil, "handle", []byte{}, 100_000_000) flt := "Values[1]" - putOracleRequest(t, cs.Hash, bc, "http://get.filter", &flt, "handle", []byte{}, 10_000_000) - putOracleRequest(t, cs.Hash, bc, "http://get.filterinv", &flt, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.filter", &flt, "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.filterinv", &flt, "handle", []byte{}, 10_000_000) checkResp := func(t *testing.T, id uint64, resp *transaction.OracleResponse) *state.OracleRequest { req, err := oracleCtr.GetRequestInternal(bc.dao, id) @@ -279,7 +279,7 @@ func TestOracleFull(t *testing.T) { t.Cleanup(orc.Shutdown) bc.setNodesByRole(t, true, noderoles.Oracle, keys.PublicKeys{acc.PrivateKey().PublicKey()}) - putOracleRequest(t, cs.Hash, bc, "http://get.1234", new(string), "handle", []byte{}, 10_000_000) + putOracleRequest(t, cs.Hash, bc, "https://get.1234", new(string), "handle", []byte{}, 10_000_000) require.Eventually(t, func() bool { return mp.Count() == 1 }, time.Second*3, time.Millisecond*200) @@ -341,43 +341,43 @@ func (c *httpClient) Get(url string) (*http.Response, error) { func newDefaultHTTPClient() oracle.HTTPClient { return &httpClient{ responses: map[string]testResponse{ - "http://get.1234": { + "https://get.1234": { code: http.StatusOK, body: []byte{1, 2, 3, 4}, }, - "http://get.4321": { + "https://get.4321": { code: http.StatusOK, body: []byte{4, 3, 2, 1}, }, - "http://get.timeout": { + "https://get.timeout": { code: http.StatusRequestTimeout, body: []byte{}, }, - "http://get.notfound": { + "https://get.notfound": { code: http.StatusNotFound, body: []byte{}, }, - "http://get.forbidden": { + "https://get.forbidden": { code: http.StatusForbidden, body: []byte{}, }, - "http://private.url": { + "https://private.url": { code: http.StatusOK, body: []byte("passwords"), }, - "http://get.big": { + "https://get.big": { code: http.StatusOK, body: make([]byte, transaction.MaxOracleResultSize+1), }, - "http://get.maxallowed": { + "https://get.maxallowed": { code: http.StatusOK, body: make([]byte, transaction.MaxOracleResultSize), }, - "http://get.filter": { + "https://get.filter": { code: http.StatusOK, body: []byte(`{"Values":["one", 2, 3],"Another":null}`), }, - "http://get.filterinv": { + "https://get.filterinv": { code: http.StatusOK, body: []byte{0xFF}, }, diff --git a/pkg/services/oracle/request.go b/pkg/services/oracle/request.go index 067b3a574..f0d5f48ee 100644 --- a/pkg/services/oracle/request.go +++ b/pkg/services/oracle/request.go @@ -102,7 +102,7 @@ func (o *Oracle) processRequest(priv *keys.PrivateKey, req request) error { } if err != nil { resp.Code = transaction.Forbidden - } else if u.Scheme == "http" { + } else if u.Scheme == "https" { r, err := o.Client.Get(req.Req.URL) switch { case err != nil: