# 12.6.3 Agregar los passwords como variables de ambiente

Se considera también una buena practica no exponer los passwords o token en código, se tienen algunas opciones para almacenar los passwords:

* Variables de ambiente.
* Azure Key Vault.

## Utilizando variables de ambiente

Puedes agregar variables de ambiente en Visual Studio, agregaremos 3 una para cada usuario con el nombre JUAN, CARLOS, MARIA.

Para utilizar las variables de ambiente en el código con la función:

```
Environment.GetEnvironmentVariable(nombre_variable) 
```

Puedes cambiar la función DadoTecleoLosSiguientesDatosDelUsuario para tomar el password de acuerdo al nombre del usuario con el siguiente código

```
  [Given(@"Tecleo los siguientes datos del usuario (.*)")]
    public void DadoTecleoLosSiguientesDatosDelUsuario(string usuario)
    {
        login.Usuario = usuario;
        string pass = Environment.GetEnvironmentVariable(usuario.ToUpper());
        login.Password = pass;
    }
```

También debes agregar las variables de ambiente a Azure Devops, Github o tu herramienta de CI/CD.  En Azure devops si la variable es Secret debes agregarla en el step de integration test.

```
- task: DotNetCoreCLI@2
  displayName: Testing Integration Test
  inputs:
    command: 'test'
    projects: '**/CaducaRest.IntegrationTest/*.csproj'
    arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/'
    publishTestResults: true
    testRunTitle: 'Integration Test'
  env:
    CARLOS: $(CARLOS)
    JUAN: $(JUAN)
    MARIA: $(MARIA)
```

Para practicar puedes cambiar el escensario de Login con un usuario

Un ejemplo sería el siguiente:

{% code title="Login.feature" %}

```gherkin
# language: es
Característica: Login
	Dado que ya existen los siguientes usuarios:
        Usuario  Nombre
	Carlos   Carlos Hernández 
	Maria    Maria Lopez
	Juan     Juan Peréz

@Login
Escenario: Login con un usuario
	Dado Que Existe un usuario con la clave Carlos
	Cuando Yo ejecuto el servicio Usuarios/Login 
	Entonces Obtengo el nombre Carlos Hernández

Escenario: Login con usuarios en Tabla
	Dado Tecleo los siguientes datos del usuario
	Cuando Yo ejecuto el servicio Usuarios/Login
	Entonces Obtengo el nombre <Nombre>

Ejemplos: 
	| Usuario		| Nombre	|
	| Maria			| Maria Lopez	|
        | Juan			| Juan Peréz	|
```

{% endcode %}

Puedes generar los pasos y comparar con mi solución en github.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://abi.gitbook.io/net-core/10.-pruebas-de-integracion/10.5-mejorando-tu-codigo/12.6.3-agregar-los-passwords-como-variables-de-ambiente.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
