Skip to content

Commit

Permalink
feat(act): fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferenc Sárai committed Jul 31, 2024
1 parent eb9b62e commit 4632819
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/bee/api/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (a *ActService) Upload(ctx context.Context, name string, data io.Reader, o
return resp, err
}

func (a *ActService) AddGrantees(ctx context.Context, name string, data io.Reader, o UploadOptions) (ActGranteesResponse, error) {
func (a *ActService) AddGrantees(ctx context.Context, data io.Reader, o UploadOptions) (ActGranteesResponse, error) {
var resp ActGranteesResponse
h := http.Header{}
h.Add(postageStampBatchHeader, o.BatchID)
Expand All @@ -53,7 +53,7 @@ func (a *ActService) GetGrantees(ctx context.Context, addr swarm.Address) (resp
return a.client.requestData(ctx, http.MethodGet, "/"+apiVersion+"/grantee/"+addr.String(), nil, nil)
}

func (a *ActService) PatchGrantees(ctx context.Context, name string, data io.Reader, addr swarm.Address, haddr swarm.Address, batchID string) (ActGranteesResponse, error) {
func (a *ActService) PatchGrantees(ctx context.Context, data io.Reader, addr swarm.Address, haddr swarm.Address, batchID string) (ActGranteesResponse, error) {
var resp ActGranteesResponse
h := http.Header{}
h.Add("swarm-postage-batch-id", batchID)
Expand Down
5 changes: 2 additions & 3 deletions pkg/bee/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ func (c *Client) DownloadActFile(ctx context.Context, a swarm.Address, opts *api
if err != nil {
return 0, nil, fmt.Errorf("download file %s: %w", a, err)
}
defer r.Close()

h := fileHasher()
size, err = io.Copy(h, r)
Expand Down Expand Up @@ -783,7 +782,7 @@ func (c *Client) UploadActFile(ctx context.Context, f *File, o api.UploadOptions

func (c *Client) AddActGrantees(ctx context.Context, f *File, o api.UploadOptions) (err error) {
h := fileHasher()
r, err := c.api.Act.AddGrantees(ctx, f.Name(), io.TeeReader(f.DataReader(), h), o)
r, err := c.api.Act.AddGrantees(ctx, io.TeeReader(f.DataReader(), h), o)
if err != nil {
return fmt.Errorf("add ACT grantees: %w", err)
}
Expand All @@ -806,7 +805,7 @@ func (c *Client) GetActGrantees(ctx context.Context, a swarm.Address) (addresses
}

func (c *Client) PatchActGrantees(ctx context.Context, pf *File, addr swarm.Address, haddr swarm.Address, batchID string) (err error) {
r, err := c.api.Act.PatchGrantees(ctx, pf.Name(), pf.DataReader(), addr, haddr, batchID)
r, err := c.api.Act.PatchGrantees(ctx, pf.DataReader(), addr, haddr, batchID)
if err != nil {
return fmt.Errorf("add ACT grantees: %w", err)
}
Expand Down
19 changes: 14 additions & 5 deletions pkg/check/act/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func NewCheck(logger logging.Logger) beekeeper.Action {

// Run executes act check
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
c.logger.Info("ACT test started")
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down Expand Up @@ -230,7 +229,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
return fmt.Errorf("node %s: PatchActGrantees: %w", upNodeName, pErr)
}
c.logger.Info("ACT grantees patched")
time.Sleep(5 * time.Second)
time.Sleep(15 * time.Second)

// list grantees after patch
// ----------------------------------------------
Expand All @@ -249,9 +248,21 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
}
c.logger.Info("ACT grantees listed after patch")

// download act file with the not enabled grantee after patch
//----------------------------------------------
// Given the grantee is patched
// When the file is downloaded from the node with the not enabled grantee
// Then the file download is denied
hG := pFile.HistroryAddress()
_, _, notGErr := client2.DownloadActFile(ctx, fileAddress, &api.DownloadOptions{Act: &act, ActPublicKey: &publisher, ActHistoryAddress: &hG})
if notGErr == nil {
return fmt.Errorf("node %s: File downloaded with wrong public key successfully - this is an error", nodeName2)
}
c.logger.Info("ACT Access denied for not enabled grantee after patch")

// download act file with the new grantee after patch
// ----------------------------------------------
// Given the grantee is patched
// Given that the grantee has been patched
// When the file is downloaded from the node with the new grantee
// Then the file is downloaded successfully
his2 := pFile.HistroryAddress()
Expand All @@ -264,7 +275,5 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
return errors.New("ACT file retrieval - hash error")
}
c.logger.Info("ACT file downloaded with the new grantee after patch")

c.logger.Info("ACT test completed")
return
}

0 comments on commit 4632819

Please sign in to comment.