Skip to content

Commit

Permalink
don't certify if URL or pubkey is empty (#6457)
Browse files Browse the repository at this point in the history
## Motivation

Fixes the issue when the poet client tries to certify despite the certifier URL is empty.
  • Loading branch information
poszu committed Nov 18, 2024
1 parent f4de865 commit 03f6f9c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ See [RELEASE](./RELEASE.md) for workflow instructions.

* [#6451](https://github.com/spacemeshos/go-spacemesh/pull/6451) Fix a possible deadloop in the beacon protocol.

* [#6457](https://github.com/spacemeshos/go-spacemesh/pull/6457) Fix trying to certify POST when certifier URL is empty.

## v1.7.6

### Upgrade information
Expand Down
2 changes: 1 addition & 1 deletion activation/poet.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ func (c *poetService) Certify(ctx context.Context, id types.NodeID) (*certifier.
return nil, err
}

if info.Certifier == nil {
if info.Certifier == nil || len(info.Certifier.Url.Host) == 0 || len(info.Certifier.Pubkey) == 0 {
return nil, ErrCertificatesNotSupported
}
return c.certifier.Certificate(ctx, id, info.Certifier.Url, info.Certifier.Pubkey)
Expand Down
39 changes: 39 additions & 0 deletions activation/poet_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,45 @@ func TestPoetClient_Certify(t *testing.T) {
_, err = poet.Certify(context.Background(), sig.NodeID())
require.ErrorIs(t, err, ErrCertificatesNotSupported)
})
t.Run("poet does not support certificate (empty certifier URL)", func(t *testing.T) {
ctrl := gomock.NewController(t)
mCertifier := NewMockcertifierService(ctrl)
client := NewMockPoetClient(ctrl)
client.EXPECT().Info(gomock.Any()).Return(
&types.PoetInfo{
Certifier: &types.CertifierInfo{
Url: &url.URL{},
Pubkey: []byte("key"),
},
},
nil,
).AnyTimes()

logger := zaptest.NewLogger(t)
poet := NewPoetServiceWithClient(nil, client, cfg, logger, testTickSize, WithCertifier(mCertifier))
_, err = poet.Certify(context.Background(), sig.NodeID())
require.ErrorIs(t, err, ErrCertificatesNotSupported)
})
t.Run("poet does not support certificate (empty certifier pubkey)", func(t *testing.T) {
ctrl := gomock.NewController(t)
mCertifier := NewMockcertifierService(ctrl)
client := NewMockPoetClient(ctrl)
url, err := url.Parse("http://poet.spacemesh")
require.NoError(t, err)
client.EXPECT().Info(gomock.Any()).Return(
&types.PoetInfo{
Certifier: &types.CertifierInfo{
Url: url,
},
},
nil,
).AnyTimes()

logger := zaptest.NewLogger(t)
poet := NewPoetServiceWithClient(nil, client, cfg, logger, testTickSize, WithCertifier(mCertifier))
_, err = poet.Certify(context.Background(), sig.NodeID())
require.ErrorIs(t, err, ErrCertificatesNotSupported)
})
}

func TestPoetClient_ObtainsCertOnSubmit(t *testing.T) {
Expand Down

0 comments on commit 03f6f9c

Please sign in to comment.