You are tasked with implementing a secure authentication system for a web application. What considerations should you make to ensure the security of user credentials and session information?
- Store passwords in plain text
- Use a secure hashing algorithm for password storage
- Use HTTP for transmitting sensitive data
- Keep session tokens in local storage
To ensure the security of user credentials and session information, you should use a secure hashing algorithm (like bcrypt) to store passwords, not store them in plain text. Additionally, sensitive data should not be transmitted over HTTP, and session tokens should be stored securely (not in local storage, which is vulnerable to cross-site scripting attacks).
What considerations should be made when deciding between using a mock and a stub in a test case?
- The complexity of the test scenario
- The need for recording method calls
- The desire to control method behavior
- The size of the test data
When deciding between using a mock and a stub in a test case, considerations should include the complexity of the test scenario, as mocks are generally more complex than stubs. Recording method calls is a characteristic of mocks, and controlling method behavior is a characteristic of stubs. The size of the test data is typically not directly related to choosing between mocks and stubs.
What is the first line of defense against injection attacks in web applications?
- Using a web application firewall (WAF).
- Escaping user input before displaying it.
- Using strong authentication mechanisms.
- Regularly updating server software.
The first line of defense against injection attacks in web applications is to escape or sanitize user input before displaying it on web pages. This prevents malicious code from being executed, protecting against common injection attacks like SQL injection and cross-site scripting (XSS).
When securing a web application using JWT, implementing ________ helps in mitigating the risk of token interception.
- Token expiration
- Strong encryption
- Public key authentication
- Rate limiting
When securing a web application with JWT (JSON Web Tokens), implementing strong encryption is crucial to mitigate the risk of token interception. Encryption ensures that the token's content remains confidential even if intercepted. Token expiration (Option 1) deals with token validity periods, while public key authentication (Option 3) is related to how JWT signatures are verified. Rate limiting (Option 4) is a measure to control access but doesn't directly address token interception.
The else if statement is used in JavaScript for ________.
- conditional execution
- error handling
- multiple comparisons
- branching based on multiple conditions
The else if statement in JavaScript is used for branching based on multiple conditions. It allows you to check additional conditions if the previous if condition is false.
You are tasked with creating tests for a complex system with multiple interacting components. How would you decide which components to mock or stub to achieve a balance between test isolation and reliability?
- Mock all components to ensure complete isolation
- Stub only the most complex components
- Mock components that are external or slow
- Stub components that are stable and well-tested
When testing a complex system, it's essential to strike a balance between test isolation and reliability. Mocking all components can lead to over-fragmented tests and make maintenance difficult. Stubbing only the most complex components may not ensure adequate coverage. To achieve this balance, you should mock components that are external or slow, as these can introduce variability and slow down tests. Stubbing components that are stable and well-tested can help reduce unnecessary complexity and speed up test execution.
What does the process object in Node.js primarily provide information about?
- Operating system processes
- Web browser processes
- File I/O processes
- Database processes
The process object in Node.js primarily provides information about operating system processes. It allows you to interact with and control the Node.js process, such as accessing command line arguments, environment variables, and exiting the process. It is not related to web browser, file I/O, or database processes.
When designing systems with Non-Blocking I/O, careful consideration must be given to avoid ________, where multiple asynchronous operations are competing for resources.
- Callback Hell
- Deadlock
- Blocking I/O
- Synchronous Execution
When designing systems with Non-Blocking I/O, careful consideration must be given to avoid "Callback Hell," also known as "Callback Pyramid" or "Callback Spaghetti." This occurs when multiple asynchronous operations are nested deeply, making code difficult to read and maintain.
How can you implement template inheritance in Pug?
- extend layout.pug
- include layout.pug
- inherit layout.pug
- template layout.pug
In Pug, template inheritance is implemented using the extend keyword followed by the name of the layout file. This allows child templates to inherit the structure and content of the specified layout file. The other options (include, inherit, and template) are not used for template inheritance in Pug.
In the context of closures, what is meant by the term 'lexical scoping' in JavaScript?
- Lexical scoping, also known as static scoping, means that the scope of a variable is determined by its position within the source code, and it is fixed at the time of the variable's definition. In JavaScript, closures have lexical scoping, which means they capture variables from the outer function based on where they are defined in the code, not where they are executed.
- Lexical scoping, also called static scoping, refers to the way variables are resolved in a program. In JavaScript closures, lexical scoping means that the scope of a variable is determined by its location in the source code, and it remains fixed once the function is defined.
- Lexical scoping, often referred to as static scoping, is a feature of closures in JavaScript. It means that a closure captures variables from its surrounding context based on their lexical location, not their runtime values. This allows closures to access variables even after the outer function has completed execution.
- In JavaScript closures, lexical scoping means that the scope of a variable is determined by its position in the code when the closure is defined, not when it is executed. This ensures that closures capture the correct variables from their enclosing scope.
Closures and Lexical Scoping