Home / Past papers / MAD2 End Term / this paper
. Which of the following best explains the relationship between the header and the signature in JWT authentication?``` header.payload.signature ```
, Celery Beat manages both the schedule and the execution, so running the Worker is redundant.``` beat_schedule ```
from the Flask app.``` .delay() ```
instead of inside
.In that case, Beat handles execution too.``` .apply_async() ``` ``` beat_schedule ```
and JavaScript
for a Vue application: File: index.html
File: app.js
Suppose the application is running on
, and the user visits the URL:
What will be rendered by the browser? [NOTE:
is divided in two images, consider them as one file content.]

index.html
app.js
```html
<div id="app">
<router-view></router-view>
</div>
```
```javascript
const Flights = {
template: `<h2>{{ result }}</h2>`,
data() {
return {
routes: [
{ city: "Delhi", connectedTo: ["Mumbai", "Pune"] },
{ city: "Indore", connectedTo: ["Bhopal", "Jaipur"] },
{ city: "Raipur", connectedTo: ["Nagpur", "Hyderabad"] },
{ city: "Rewa", connectedTo: ["Delhi", "Indore", "Raipur"] }
],
result: ""
};
},
created() {
const destination = this.$route.params.city.toLowerCase();
for (let i = 0; i < this.routes.length; i++) {
const connections = this.routes[i].connectedTo;
for (let j = 0; j < connections.length; j++) {
if (connections[j].toLowerCase() === destination) {
this.result = this.routes[i].city;
break;
}
}
if (this.result) {
break;
}
}
}
};
```
```
http://localhost:8080
```
```
http://localhost:8080/#/raipur
```
app.js
```javascript
const router = new VueRouter({
routes: [
{
path: "/:city",
component: Flights
}
]
});
new Vue({
el: "#app",
router
});
```
file:index.html
Select all statements that correctly describe the console output:```javascript
new Vue({
el: "#app",
data: {
message: "Hello"
},
beforeCreate() {
console.log("1:", this.message);
},
created() {
console.log("2:", this.message);
},
beforeMount() {
console.log("3:", this.$el.textContent);
},
mounted() {
console.log("4:", this.$el.textContent);
}
});
```
```html
<div id="app">{{ message }}</div>
```
undefined

hello

hello

hello
Assume the API returns:
Complete the missing code so that all course names are rendered correctly. Which of the following code snippets can correctly replace
?```html
<div id="app">
<ul>
<!-- Missing Code -->
</ul>
</div>
<script>
new Vue({
el: '#app',
data: {
courses: []
},
async mounted() {
const response = await fetch('https://example.com/api/courses')
this.courses = await response.json()
}
})
</script>
```
```json
[
{ "id": 1, "name": "MAD-2" },
{ "id": 2, "name": "DBMS" }
]
```
```html
<!-- Missing Code -->
```
```html
<li v-for="course in courses" :key="course.id">
{{ course.name }}
</li>
```
```html
<li v-for="(course, index) in courses" :key="index">
{{ course.name }}
</li>
```
```html
<li v-if="course in courses">
{{ course.name }}
</li>
```
```html
<li v-for="courses in course">
{{ courses.name }}
</li>
```
A client first accesses
and then tries to access
. Which of the following statements are correct?```python
from flask import Flask, jsonify
from flask_jwt_extended import JWTManager, create_access_token, \
jwt_required
app = Flask(__name__)
app.config["JWT_SECRET_KEY"] = "secret"
jwt = JWTManager(app)
@app.route("/token")
def token():
access_token = create_access_token(identity="Ravi")
return jsonify(access_token=access_token)
@app.route("/dashboard")
@jwt_required()
def dashboard():
return jsonify(message="Dashboard Access Granted")
```
/token
/dashboard
can only be accessed if a valid JWT token is sent with the request./dashboard
is automatically stored by Flask and reused for future requests./token
header while accessing protected routes.Authorization
about its output:

TRUE
```javascript
const value = "global";
const obj = {
value: "objectValue",
regularMethod: function () {
console.log(this.value);
},
arrowMethod: () => {
console.log(this.value);
},
nested: {
value: "nestedValue",
regularInNested: function () {
console.log(this.value);
},
arrowInNested: () => {
console.log(this.value);
}
},
delayedRegular: function () {
setTimeout(function () {
console.log(this.value);
}, 100);
},
delayedArrow: function () {
setTimeout(() => {
console.log(this.value);
}, 100);
}
};
```
```javascript
obj.regularMethod();
obj.arrowMethod();
obj.nested.regularInNested();
obj.nested.arrowInNested();
obj.delayedRegular();
obj.delayedArrow();
```
logs "objectValue"``` obj.regularMethod() ```
logs "objectValue"``` obj.arrowMethod() ```
logs "nestedValue"``` obj.nested.regularInNested() ```
logs 
``` obj.nested.arrowInNested() ``` undefined
logs "objectValue"``` obj.delayedRegular() ```
logs "objectValue"``` obj.delayedArrow() ```
Which of the following statements are correct? (Select all that apply)```python
app.config["JWT_SECRET_KEY"] = "my-secret"
jwt = JWTManager(app)
@jwt.user_identity_loader
def load(user):
return user.username
@jwt.user_lookup_loader
def user_lookup(_jwt_header, jwt_data):
identity = jwt_data["sub"]
return User.query.filter_by(username=identity).one_or_none()
@app.route('/login', methods=["POST"])
def login():
user = User.query.filter_by(username="u1").one_or_none()
token = create_access_token(identity=user)
return {"access_token": token}
@app.route('/dashboard')
@jwt_required()
def dashboard():
return {
"username": current_user.username
}
```
decorator ensures that only requests with a valid JWT can access
.``` @jwt_required() ``` /dashboard
determines what value is stored in the "sub" field of the JWT.``` user_identity_loader ```
is removed,
will not be automatically populated.``` user_lookup_loader ``` current_user
directly stores the entire user object inside the JWT.```python create_access_token(identity=user) ```
object is reconstructed using the identity extracted from the JWT.current_user
will still execute but
will be None./dashboard current_user
would make the task run faster by giving it more CPU cores.``` .delay() ```

```javascript
const calculator = {
value: 10,
add(a, b) {
return this.value + a + b;
}
};
const rawAdd = calculator.add;
const boundAdd = calculator.add.bind({ value: 100 }, 5);
console.log(rawAdd(1, 2));
console.log(boundAdd(10));
console.log(calculator.add.apply({ value: 50 }, [1, 2]));
```
evaluates to 
``` rawAdd(1, 2) ``` NaN
evaluates to 
``` boundAdd(10) ``` 115
throws a 
```
calculator.add.apply({ value: 50 }, [1, 2])
```
TypeError
evaluates to 
```
calculator.add.apply({ value: 50 }, [1, 2])
```
53
| Column I | Column II | | :------- | :-------- | | 1. Unit Testing | A. Testing application behaviour across different browsers | | 2. E2E Testing | B. Commonly used for writing and running tests | | 3. Cross-Browser Testing | C. Testing individual Vue components independently | | 4. Jest / Mocha / Chai | D. Testing a complete application flow including backend interaction |

| Column I | Column II | |---|---| | 1. First Contentful Paint (FCP) | A. Measures unexpected movement of page elements | | 2. Largest Contentful Paint (LCP) | B. Measures how long the page is blocked from responding to user interaction | | 3. Total Blocking Time (TBT) | C. Measures when something first appears on the screen | | 4. Cumulative Layout Shift (CLS) | D. Measures when the largest visible content is rendered |

```javascript
const products = [
{ name: "Laptop", price: 1200, inStock: true },
{ name: "Mouse", price: 25, inStock: false },
{ name: "Keyboard", price: 75, inStock: true },
{ name: "Monitor", price: 300, inStock: false }
];
const result = products.filter(item => item.inStock && item.price < 500);
```
```json
{ "name": "Keyboard", "price": 75, "inStock": true }
```
```
[[{ name: "Laptop", price: 1200, inStock: true }, { name: "Keyboard", price: 75, inStock: true }]]
```
```
[[{ name: "Keyboard", price: 75, inStock: true }]]
```
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 100px;
height: 100px;
background-color: lightblue;
margin: 10px;
border: 1px solid black;
}
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-items: flex-start;
align-content: flex-start;
height: 300px;
border: 2px solid red;
}
</style>
</head>
<body>
<div class="container">
<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>
<div class="box">Box 4</div>
<div class="box">Box 5</div>
<div class="box">Box 6</div>
</div>
</body>
</html>
```
The developer wants to view the app in the browser locally for development. They run the following command: bash:
Which of the following best describes what happens and what the developer should have run instead?```json
{
"name": "my-vue-app",
"version": "0.1.0",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"vue": "^2.6.14"
},
"devDependencies": {
"@vue/cli-service": "^5.0.0",
"babel-eslint": "^10.1.0"
}
}
```
```
npm run build
```
launches the app on
; the developer should have run npm start to compile for production instead.``` npm run build ``` ``` localhost:8080 ```
compiles and bundles the app for production into a
folder — it does not start a local server. The developer should have run
instead.``` npm run build ``` /dist ``` npm run serve ```
is correct for local development;
is only used for deploying to a server.``` npm run build ``` ``` npm run serve ```
and
do the same thing — both launch the app at 
``` npm run build ``` ``` npm run serve ``` ``` localhost:8080 ```
What will be output on the browser’s console?```javascript
function outerFunc() {
const val1 = 10;
var val2 = 20;
function innerFunc() {
var val2 = 30;
console.log(val1)
console.log(val2)
}
innerFunc()
console.log(val1)
console.log(val2)
}
outerFunc()
```
``` 10 20 10 30 ```

``` 10 20 10 20 ```

``` 10 30 10 20 ```

```javascript const numbers = [10, 20, 30, 40, 50]; const [num1, , num2, ...rest] = numbers; const [a = 100, b = 200] = [undefined, 0]; console.log(num1, num2, rest); console.log(a, b); ```
Which of the following statements correctly describes what happens in Tab 2?```javascript
// Executed in Tab 1
localStorage.setItem("theme", "dark");
sessionStorage.setItem("cart", "3-items");
```
and
return their respective values.```javascript
localStorage.getItem("theme")
```
```javascript
sessionStorage.getItem("cart")
```
returns "dark", but
returns null.```javascript
localStorage.getItem("theme")
```
```javascript
sessionStorage.getItem("cart")
```
returns "3-items", but
returns null.```javascript
sessionStorage.getItem("cart")
```
```javascript
localStorage.getItem("theme")
```
Note: All three image above are of one html. Based on the above data, answer the given subquestions.

Based on the above data, answer the given subquestions.
gets its own
binding.```javascript
setTimeout(function(){})
```
this
from the surrounding lexical scope.this
automatically binds
to the surrounding object.``` setTimeout ``` this
in
, it will print "Rahul".``` setTimeout ``` ``` normalFunction ```

component

, what values are logged by the two
statements, immediately after commit and dispatch are called (before the 1-second timeout completes)?``` handleClick() ``` ``` console.log ```
is defined as a
while
is defined as an
?``` increment ``` mutation ``` incrementAsync ``` action
