Skip to content

Commit

Permalink
refactor: add headers
Browse files Browse the repository at this point in the history
  • Loading branch information
kopi-solarpunk committed May 16, 2024
1 parent 9c9289a commit ce2791d
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 30 deletions.
4 changes: 4 additions & 0 deletions pkg/api/dynamicaccess.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package api

import (
Expand Down
4 changes: 4 additions & 0 deletions pkg/dynamicaccess/accesslogic.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess

import (
Expand Down
49 changes: 19 additions & 30 deletions pkg/dynamicaccess/accesslogic_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess_test

import (
Expand All @@ -12,6 +16,7 @@ import (
"github.com/ethersphere/bee/v2/pkg/dynamicaccess"
kvsmock "github.com/ethersphere/bee/v2/pkg/kvs/mock"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/stretchr/testify/assert"
)

// Generates a new test environment with a fix private key
Expand Down Expand Up @@ -133,9 +138,7 @@ func TestDecryptRef_Error(t *testing.T) {
s := kvsmock.New()
al := setupAccessLogic()
err := al.AddPublisher(ctx, s, &id0.PublicKey)
if err != nil {
t.Errorf("AddPublisher: expected no error, got %v", err)
}
assert.NoError(t, err)

expectedRef := "39a5ea87b141fe44aa609c3327ecd896c0e2122897f5f4bbacf74db1033c5559"

Expand All @@ -156,19 +159,14 @@ func TestAddPublisher(t *testing.T) {

al := setupAccessLogic()
err := al.AddPublisher(ctx, s, &id0.PublicKey)
if err != nil {
t.Errorf("AddPublisher: expected no error, got %v", err)
}
assert.NoError(t, err)

decodedSavedLookupKey, err := hex.DecodeString(savedLookupKey)
if err != nil {
t.Errorf("DecodeString: expected no error, got %v", err)
}
assert.NoError(t, err)

encryptedAccessKey, err := s.Get(ctx, decodedSavedLookupKey)
if err != nil {
t.Errorf("Lookup: expected no error, got %v", err)
}
assert.NoError(t, err)

decodedEncryptedAccessKey := hex.EncodeToString(encryptedAccessKey)

// A random value is returned so it is only possibly to check the length of the returned value
Expand All @@ -194,44 +192,35 @@ func TestAddNewGranteeToContent(t *testing.T) {
s := kvsmock.New()
al := setupAccessLogic()
err := al.AddPublisher(ctx, s, &id0.PublicKey)
if err != nil {
t.Errorf("AddNewGrantee: expected no error, got %v", err)
}
assert.NoError(t, err)

err = al.AddGrantee(ctx, s, &id0.PublicKey, &id1.PublicKey, nil)
if err != nil {
t.Errorf("AddNewGrantee: expected no error, got %v", err)
}
assert.NoError(t, err)

err = al.AddGrantee(ctx, s, &id0.PublicKey, &id2.PublicKey, nil)
if err != nil {
t.Errorf("AddNewGrantee: expected no error, got %v", err)
}
assert.NoError(t, err)

lookupKeyAsByte, err := hex.DecodeString(publisherLookupKey)
if err != nil {
t.Errorf("AddNewGrantee: expected no error, got %v", err)
}
assert.NoError(t, err)

result, _ := s.Get(ctx, lookupKeyAsByte)
hexEncodedEncryptedAK := hex.EncodeToString(result)
if len(hexEncodedEncryptedAK) != 64 {
t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK))
}

lookupKeyAsByte, err = hex.DecodeString(firstAddedGranteeLookupKey)
if err != nil {
t.Errorf("AddNewGrantee: expected no error, got %v", err)
}
assert.NoError(t, err)

result, _ = s.Get(ctx, lookupKeyAsByte)
hexEncodedEncryptedAK = hex.EncodeToString(result)
if len(hexEncodedEncryptedAK) != 64 {
t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK))
}

lookupKeyAsByte, err = hex.DecodeString(secondAddedGranteeLookupKey)
if err != nil {
t.Errorf("AddNewGrantee: expected no error, got %v", err)
}
assert.NoError(t, err)

result, _ = s.Get(ctx, lookupKeyAsByte)
hexEncodedEncryptedAK = hex.EncodeToString(result)
if len(hexEncodedEncryptedAK) != 64 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/dynamicaccess/controller.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess

import (
Expand Down
4 changes: 4 additions & 0 deletions pkg/dynamicaccess/controller_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess_test

import (
Expand Down
4 changes: 4 additions & 0 deletions pkg/dynamicaccess/grantee.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess

import (
Expand Down
4 changes: 4 additions & 0 deletions pkg/dynamicaccess/grantee_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess_test

import (
Expand Down
4 changes: 4 additions & 0 deletions pkg/dynamicaccess/history.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess

import (
Expand Down
4 changes: 4 additions & 0 deletions pkg/dynamicaccess/history_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess_test

import (
Expand Down
3 changes: 3 additions & 0 deletions pkg/dynamicaccess/mock/accesslogic.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mock

type AccessLogicMock struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/dynamicaccess/session.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess

import (
Expand Down
4 changes: 4 additions & 0 deletions pkg/dynamicaccess/session_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dynamicaccess_test

import (
Expand Down
4 changes: 4 additions & 0 deletions pkg/kvs/mock/kvs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package mock

import (
Expand Down

0 comments on commit ce2791d

Please sign in to comment.