mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 18:48:08 +00:00 
			
		
		
		
	Add context-aware functions to vault/api (#14388)
This commit is contained in:
		 Anton Averchenkov
					Anton Averchenkov
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							fea828993c
						
					
				
				
					commit
					8234a663e7
				
			| @@ -1,6 +1,7 @@ | ||||
| package command | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"testing" | ||||
|  | ||||
| 	log "github.com/hashicorp/go-hclog" | ||||
| @@ -45,7 +46,7 @@ func TestPathMap_Upgrade_API(t *testing.T) { | ||||
| 	} | ||||
|  | ||||
| 	// Create an app-id | ||||
| 	_, err = client.Logical().Write("auth/app-id/map/app-id/test-app-id", map[string]interface{}{ | ||||
| 	_, err = client.Logical().WriteWithContext(context.Background(), "auth/app-id/map/app-id/test-app-id", map[string]interface{}{ | ||||
| 		"policy": "test-policy", | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| @@ -53,7 +54,7 @@ func TestPathMap_Upgrade_API(t *testing.T) { | ||||
| 	} | ||||
|  | ||||
| 	// Create a user-id | ||||
| 	_, err = client.Logical().Write("auth/app-id/map/user-id/test-user-id", map[string]interface{}{ | ||||
| 	_, err = client.Logical().WriteWithContext(context.Background(), "auth/app-id/map/user-id/test-user-id", map[string]interface{}{ | ||||
| 		"value": "test-app-id", | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| @@ -61,7 +62,7 @@ func TestPathMap_Upgrade_API(t *testing.T) { | ||||
| 	} | ||||
|  | ||||
| 	// Perform a login. It should succeed. | ||||
| 	_, err = client.Logical().Write("auth/app-id/login", map[string]interface{}{ | ||||
| 	_, err = client.Logical().WriteWithContext(context.Background(), "auth/app-id/login", map[string]interface{}{ | ||||
| 		"app_id":  "test-app-id", | ||||
| 		"user_id": "test-user-id", | ||||
| 	}) | ||||
| @@ -70,20 +71,20 @@ func TestPathMap_Upgrade_API(t *testing.T) { | ||||
| 	} | ||||
|  | ||||
| 	// List the hashed app-ids in the storage | ||||
| 	secret, err := client.Logical().List("auth/app-id/map/app-id") | ||||
| 	secret, err := client.Logical().ListWithContext(context.Background(), "auth/app-id/map/app-id") | ||||
| 	if err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
| 	hashedAppID := secret.Data["keys"].([]interface{})[0].(string) | ||||
|  | ||||
| 	// Try reading it. This used to cause an issue which is fixed in [GH-3806]. | ||||
| 	_, err = client.Logical().Read("auth/app-id/map/app-id/" + hashedAppID) | ||||
| 	_, err = client.Logical().ReadWithContext(context.Background(), "auth/app-id/map/app-id/"+hashedAppID) | ||||
| 	if err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	// Ensure that there was no issue by performing another login | ||||
| 	_, err = client.Logical().Write("auth/app-id/login", map[string]interface{}{ | ||||
| 	_, err = client.Logical().WriteWithContext(context.Background(), "auth/app-id/login", map[string]interface{}{ | ||||
| 		"app_id":  "test-app-id", | ||||
| 		"user_id": "test-user-id", | ||||
| 	}) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user